【发布时间】:2010-11-01 15:30:28
【问题描述】:
我想知道如何从每个<p> 标记中检索所有结果。
import re
htmlText = '<p data="5" size="4">item1</p><p size="4">item2</p><p size="4">item3</p>'
print re.match('<p[^>]*size="[0-9]">(.*?)</p>', htmlText).groups()
结果:
('item1', )
我需要什么:
('item1', 'item2', 'item3')
【问题讨论】:
-
-1 用于尝试使用正则表达式解析非常规语言。
-
同意,不是有一个以解析html而闻名的python库吗?美丽汤? htmllib?
-
感谢您的回复。我需要一种 python 方法来从一个小 html 中打印出 p 标记的所有值,而无需在服务器中安装任何新内容。