【发布时间】:2012-05-10 18:44:05
【问题描述】:
我有一个 html 表格。
在那张桌子上我有
<td>abc</td><a>www.abc.com</a>
如何通过匹配 td 的值来获取链接值?
例如:如何使用 lxml 搜索 tect abc 获得 www.abc.com 的值?
【问题讨论】:
我有一个 html 表格。
在那张桌子上我有
<td>abc</td><a>www.abc.com</a>
如何通过匹配 td 的值来获取链接值?
例如:如何使用 lxml 搜索 tect abc 获得 www.abc.com 的值?
【问题讨论】:
a/text() 获取文本
a/@href 获取 attr(在这种情况下为href)
UPD
>>> from lxml import etree
>>> etree.fromstring('<html><td>abc</td><a>www.abc.com</a></html>').xpath("//td/following-sibling::a/text()")
['www.abc.com']
【讨论】: