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

打印内容:

相关推荐
用户2986985301414 小时前
HTML 转 Word 指南:新手入门教程
人工智能·后端·python
Livia要学习15 小时前
Python面向对象三大特性:封装、继承、多态
开发语言·python
Csvn15 小时前
🐍 Day1 : Python 环境搭建 — 现代 Python 工作流
后端·python
杨_晨15 小时前
LLM输出康熙部首冲突
数据库·python·mysql·ai
渣男教父15 小时前
Python-lxml 与 XPath 实战
python·编程语言
42tr_k15 小时前
用 OpenDataLoader PDF 搭一个兼容 MinerU 的解析服务
后端·python
circuitsosk15 小时前
长文本与高并发下的Token“瘦身”策略:Prompt压缩与上下文窗口优化
java·前端·python·prompt·上下文窗口·token优化
鹿鹿学长15 小时前
国赛备赛第一课:高数、线代、概率统计在历年赛题中的真实出镜率盘点
python·自动化
整个江湖15 小时前
Python 工程实践:时间区间解析、时区归一化与边界测试
python
2501_9095091015 小时前
DAY 43
python