在html选项卡中使用lxml获取href的值

2024-09-30 10:33:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个html表格。
在那张桌子上

<td>abc</td><a>www.abc.com</a>  

如何使用匹配td的值来获得链接值?在

例如:如何获得www.abc.com网站用lxml搜索tect-abc?在


Tags: com网站链接htmlwwwlxml表格td
1条回答
网友
1楼 · 发布于 2024-09-30 10:33:28

a/text()获取文本

a/@href获取attr(在本例中是href

升级版

>>> 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

相关问题 更多 >

    热门问题