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

打印内容:

相关推荐
FreakStudio3 小时前
不用装软件!这款MicroPython浏览器 IDE :让你在手机上也能调试树莓派 Pico
python·单片机·嵌入式·电子diy·tinyml
m0_743470373 小时前
使用Python进行PDF文件的处理与操作
jvm·数据库·python
数据科学小丫5 小时前
Python 数据存储操作_数据存储、补充知识点:Python 与 MySQL交互
数据库·python·mysql
Knight_AL5 小时前
Nacos 启动问题 Failed to create database ’D:\nacos\nacos\data\derby-data’
开发语言·数据库·python
查古穆7 小时前
python进阶-Pydantic模型
开发语言·python
佳木逢钺7 小时前
PyQt界面美化系统高级工具库:打造现代化桌面应用的完整指南
python·pyqt
工頁光軍7 小时前
基于Python的Milvus完整使用案例
开发语言·python·milvus
Csvn7 小时前
特殊方法与运算符重载
python
xht08328 小时前
PHP vs Python:编程语言终极对决
开发语言·python·php
2401_879693878 小时前
使用Python控制Arduino或树莓派
jvm·数据库·python