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

打印内容:

相关推荐
Warson_L4 分钟前
Dictionary
python
寒山李白2 小时前
解决 python-docx 生成的 Word 文档打开时弹出“无法读取内容“警告
python·word·wps·文档·docx·qoder
2401_832365523 小时前
JavaScript中rest参数(...args)取代arguments的优势
jvm·数据库·python
Sirius.z3 小时前
第J3周:DenseNet121算法详解
python
2301_779622413 小时前
Go语言怎么用信号量控制并发_Go语言semaphore信号量教程【入门】
jvm·数据库·python
2301_766283443 小时前
c++如何将控制台输出保存到文件_cout重定向到txt【详解】
jvm·数据库·python
小康小小涵5 小时前
基于ESP32S3实现无人机RID模块底层源码编译
linux·开发语言·python
lzjava20245 小时前
Python的函数
开发语言·python
Awesome Baron6 小时前
skill、tool calling、MCP区别
开发语言·人工智能·python
测试员周周6 小时前
【AI测试系统】第4篇:告别硬编码!基于 Markdown + Python 的 Skill 引擎设计:让 AI 测试系统拥有无限扩展的“灵魂”
人工智能·python·测试