Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 html 表。 在那张桌子上我有
<td>abc</td><a>www.abc.com</a>
如何使用匹配 td 的值来获取链接值?
例如:我怎样才能获得 www.abc.com 使用 lxml 搜索 tect abc 的值?
a/text()获取文本
a/text()
a/@href获得 attr (href在这种情况下)
a/@href
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']
XPath 1.0