我正在抓取http://stats.espncricinfo.com/ci/engine/records/index.html?id=2;type=team
我需要的是附加到 XPath 表达式的链接
/html/body/div[1]/div[3]/div[4]/table/tbody/tr/td[1]/div[2]/table[1]/tbody/tr/td/ul[2]/li/a[2]
在页面中它是由 "One-day Internationals"
标记的元素在按年份排列的比赛结果列表下。上述表达式是使用 Firefox 扩展 Firebug 获得的。
但是它返回一个空列表。尝试过使用替代 xpath 表达式,例如
//div[@id="ciHomeContentlhs"]/table/tbody/tr/td[1]/div/table[2]/tbody/tr/td/ul/li/a[2]/@href
结果相同。
Xpath 表达式
//div[@id="ciHomeContentlhs"]/table
正在给我 table 。然而
//div[@id="ciHomeContentlhs"]/table/tbody
返回一个空列表。我已经测试了 xpath 表达式
http://videlibri.sourceforge.net/cgi-bin/xidelcgi它显示了所需的 href
或节点作为输出。我似乎无法在 Python
上类。
最佳答案
<tbody>
元素不是初始 HTML
的一部分源 - 它是由浏览器解析器生成的,因此您不应该在 XPath
中使用它表达。
您可以使用链接文本来匹配确切的元素:
//a[text()="One-Day Internationals"]
关于python-3.x - 在 scrapy 中返回空列表的 XPath 表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44195814/