【发布时间】:2010-12-17 16:23:04
【问题描述】:
我正在使用此代码查找页面中所有有趣的链接:
soup.findAll('a', href=re.compile('^notizia.php\?idn=\d+'))
而且它的工作做得很好。不幸的是,在那个 a 标签里面有很多嵌套标签,比如 font、b 和不同的东西......我想得到只是文本内容,没有任何其他 html 标记。
链接示例:
<A HREF="notizia.php?idn=1134" OnMouseOver="verde();" OnMouseOut="blu();"><FONT CLASS="v12"><B>03-11-2009: <font color=green>CCS Ingegneria Elettronica-Sportello studenti ed orientamento</B></FONT></A>
当然它很丑(而且标记并不总是一样!),我想得到:
03-11-2009: CCS Ingegneria Elettronica-Sportello studenti ed orientamento
在文档中说要在 findAll 方法中使用text=True,但它会忽略我的正则表达式。为什么?我该如何解决?
【问题讨论】:
-
PyQuery 听起来是个很酷的替代方案:pypi.python.org/pypi/pyquery
标签: python beautifulsoup html-parsing html-content-extraction