用正则表达式匹配HTML标签
在网络爬虫和数据分析中,用到正则表达式匹配HTML标签的情况非常多。本文将介绍如何使用Python re模块进行HTML标签匹配。以下是示例代码:
import re
# HTML标签匹配表达式
pattern = re.compile('<.*?>')
# 测试文本
text = '<html><head><title>Page Title</title></head><body><h1>This is a Heading</h1><p>This is a paragraph.&l