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

打印内容:

相关推荐
Circ.30 分钟前
文本相似性对比python代码
开发语言·python·相似度
Ahtacca40 分钟前
基于决策树算法的动物分类实验:Mac环境复现指南
python·算法·决策树·机器学习·ai·分类
萌>__<新1 小时前
AI聊天助手-测试报告
人工智能·python
sg_knight1 小时前
设计模式实战:观察者模式(Observer)
python·观察者模式·设计模式
Humbunklung1 小时前
WMO 天气代码(Code Table 4677)深度解析与应用报告
开发语言·数据库·python
weixin_449290011 小时前
uv打包Python为exe步骤
开发语言·python·uv
书到用时方恨少!1 小时前
Python threading 使用指南:并发编程的轻骑兵
python·多线程·thread·多任务
努力学习_小白1 小时前
数据增强——tensorflow
人工智能·python·tensorflow
m0_694845571 小时前
marimo搭建教程:替代Jupyter的交互式开发工具
服务器·ide·python·docker·jupyter·github
csdn2015_2 小时前
Set<String> 类型取第一条记录
开发语言·windows·python