我有这个 xpath 查询:
/html/body//tbody/tr[*]/td[*]/a[@title]/@href
它提取所有带有 title 属性的链接 - 并href
在FireFox 的 Xpath 检查器插件中提供。
但是,我似乎无法将它与lxml
.
from lxml import etree
parsedPage = etree.HTML(page) # Create parse tree from valid page.
# Xpath query
hyperlinks = parsedPage.xpath("/html/body//tbody/tr[*]/td[*]/a[@title]/@href")
for x in hyperlinks:
print x # Print links in <a> tags, containing the title attribute
lxml
这不会从(空列表)产生任何结果。
如何在 Python 下获取href
包含属性标题的超链接的文本(链接) ?lxml