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

打印内容:

相关推荐
打工仔折腾 AI13 小时前
Docker镜像分层与卷挂载到底怎么工作:一次文件系统层面的实测分析
运维·人工智能·后端·python·docker·容器·性能优化
老歌老听老掉牙13 小时前
麻花钻锥面后刀面数学模型的完整推导与数值求解
python·钻头·后刀面
墨染天姬13 小时前
【人工智能训练师】python语法二
开发语言·人工智能·python
ikun_文14 小时前
Python高级特性
python
用户8721850124315 小时前
港股投资者必备:三大数据源对比,哪种最适合实时行情与回测?
python
溪语流沙15 小时前
【Web全栈进阶】Alembic数据库迁移:改表结构不再删库
前端·数据库·python·elasticsearch·postgresql
Evan_Lai15 小时前
(一)独热编码、标签编码、目标编码、序数编码详解
python·机器学习
用户76241175670515 小时前
第二章 Python语言基础
python
129Lab15 小时前
BMS 核心算法:SOC 估算从安时积分到 LSTM-UKF 串级融合的 30 年演进(附 Python 实现)
python·算法·lstm·python3.11·bms·soc估算
129Lab15 小时前
电池热管理仿真的AI加速:用Python+PINN物理信息神经网络替代传统CFD的可行性探索
pytorch·python·cfd·pinn·物理信息神经网络·仿真加速·电池热管理