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

打印内容:

相关推荐
北斗落凡尘11 小时前
如何使用LangGraph(1)
python·langchain
Livia要学习12 小时前
Python装饰器
开发语言·python
circuitsosk13 小时前
向量数据库选型与性能压测:Milvus、Pinecone、Chroma在真实业务下的对比
数据库·python·pinecone·milvus·向量数据库·chroma
雾时之林13 小时前
python--字符串
开发语言·python
战略性的菠萝14 小时前
研究生基本功-Python快速入门(一)
python
鬼手点金14 小时前
与LLM结合的主流智能爬虫框架
爬虫·python·llm·post·request·firecrawl·crawl4ai
月光船幽幽14 小时前
门控函数SHS阈值与调制机制解析
人工智能·python·算法
测试199814 小时前
2026全新软件测试面试八股文(含答案+文档)
自动化测试·软件测试·python·测试工具·面试·职场和发展·测试用例
Zane199414 小时前
map 比推导式快"是真的吗?一文讲透 map、filter、reduce 与 lambda 的真实性能与设计取舍
后端·python
过期的秋刀鱼!14 小时前
带替换的采样
人工智能·python·算法·决策树·机器学习