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

打印内容:

相关推荐
min(a,b)3 小时前
学习第17天:Agent Memory 与 MCP 协议
python·学习
CodeBlog-star4 小时前
LLM安全实战:提示词注入与越狱攻击防御指南
python·agent·提示词攻击·越狱攻击
小柯南敲键盘4 小时前
电商图片翻译工具推荐,批量处理主图视频字幕,免费试用
大数据·人工智能·python·音视频
比高创意品牌策划设计5 小时前
零售卖场设计软件用CAD还是SketchUp还是酷家乐
python
迷迭香yy6 小时前
行业板块轮动因子实战从板块资金到因子建模的本地化Python全流程
数据库·人工智能·python
W_326007 小时前
Python文件进阶:一维数据与 CSV 文件读写
开发语言·python
yaoxin5211237 小时前
497. Java 反射 - 使用反射读取注解
java·开发语言·python
2019一路前行8 小时前
Python 函数式编程
开发语言·python
专注仿真8 小时前
问答大模型技术方案算法实现-RAPTOR树构建算法与BEG集成使用
python·算法
从小就看凹凸曼^o^10 小时前
Python基础5 - 字典与集合:(1)字典
开发语言·python