我正在尝试从该网站抓取目录,http://www.soccerstats.com/latest.asp?league=england 。我在 python 中使用 scrapy 来获取该表中的详细信息。
<div id="league-table-data" style="text-align:center;clear:both;">
</div>
我尝试过很多xpath表达式。首先,我只是尝试使用
在该表中首先获取团队名称hxs.select('//div[contains(@id, "league-table")]/div[descendant::td[contains(@align, "left")]]/a/text()').extract()
但是,它返回一个空列表。有什么想法可以让它发挥作用吗?谢谢。
最佳答案
看起来你只需要:
>>> hxs.select('//*[@id="league-table-data"]/table/tr/td/a/text()').extract()
[u'Manchester Utd', u'Manchester City', u'Chelsea', u'Arsenal', u'Tottenham', u'Everton', u'Liverpool', u'West Bromwich', u'Swansea City', u'West Ham Utd', u'Norwich City', u'Fulham', u'Stoke City', u'Southampton', u'Aston Villa', u'Newcastle Utd', u'Sunderland', u'Wigan Athletic', u'Reading', u'QP Rangers']
关于python - 无法获取用于屏幕抓取的 xpath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17129953/