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()

打印内容:

相关推荐
韩师傅7 小时前
当你的甲方吐槽天空不够蓝,你应该如何应对
python·计算机视觉
Warson_L7 小时前
python的类&继承
python
Warson_L7 小时前
类型标注/type annotation
python
ThreeS9 小时前
手搓MiniVLA全实战教程-一步一步用pytorch解释原理与思路
人工智能·python
金銀銅鐵11 小时前
[Python] 模 n 乘法的逆元计算器
python·数学·游戏
aqi0011 小时前
15天学会AI应用开发(十)把文本嵌入模型换成国产模型
人工智能·python·ai编程
金銀銅鐵1 天前
[Python] 扩展欧几里得算法
python·数学·算法
Duckdblab1 天前
DuckDB 性能调优终极指南:打造闪电般的分析体验
python
带派擂总1 天前
Python全栈开发精华版最全合集(包含各种面试题) Day24_异常和错误
python