python-正则表达试-实践1

匹配html标签中的任意标签内数据

  1. 匹配所有包含'oo'的单词

    python 复制代码
    import re
    text = "JGood is a handsome boy, he is cool, clever, and so on..."
    re.findall(r'\w*oo\w*', text) 
  2. 匹配 html中title里面的内容

    原文:

python 复制代码
import re
file = r'./202304.html'
f = open(file,'r',encoding='utf-8')
origin_content = f.read()
#r'<title>(.*)</title>'  效果一样
result = re.findall(r'<title>(.*?)</title>',origin_content)
print(result)
f.close()

打印内容:

相关推荐
该用户已不存在1 小时前
Mojo vs Python vs Rust: 2025年搞AI,该学哪个?
后端·python·rust
站大爷IP3 小时前
Java调用Python的5种实用方案:从简单到进阶的全场景解析
python
用户8356290780519 小时前
从手动编辑到代码生成:Python 助你高效创建 Word 文档
后端·python
c8i9 小时前
python中类的基本结构、特殊属性于MRO理解
python
liwulin05069 小时前
【ESP32-CAM】HELLO WORLD
python
Doris_202310 小时前
Python条件判断语句 if、elif 、else
前端·后端·python
Doris_202310 小时前
Python 模式匹配match case
前端·后端·python
这里有鱼汤10 小时前
Python量化实盘踩坑指南:分钟K线没处理好,小心直接亏钱!
后端·python·程序员
大模型真好玩11 小时前
深入浅出LangGraph AI Agent智能体开发教程(五)—LangGraph 数据分析助手智能体项目实战
人工智能·python·mcp
测试老哥11 小时前
Selenium 使用指南
自动化测试·软件测试·python·selenium·测试工具·职场和发展·测试用例