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

打印内容:

相关推荐
宸津-代码粉碎机6 小时前
微服务线上踩坑复盘:接口超时、负载倾斜隐形问题根治方案(生产级配置)
java·大数据·人工智能·python·spring
速易达网络6 小时前
Python + Tkinter 实现基于 TCP/IP 的局域网聊天工具
python·信息与通信
多多鼠6 小时前
System Prompt 的“版本漂移”问题:从变更管理到 A/B 测试体系
开发语言·网络·人工智能·python·langchain
昔我往昔6 小时前
pytest日志问题排查记录
python·pytest
Python自动化直播6 小时前
用 Python 爬虫给 AI 直播间做数据反馈机制
人工智能·python·ai·直播
努力学习的代码小白7 小时前
源码学习04
python
Ray Wang7 小时前
Context上下文工程
python·学习·ai编程
梦影_8 小时前
Langchain简单快速上手教程(五)——聊天模型之流式传输
java·数据库·人工智能·python·langchain
ai2work8 小时前
17 · composer 进阶
python
L@ncor8 小时前
第二章 智能体发展史 · 学习笔记
人工智能·python