python - 无法获取用于屏幕抓取的 xpath

标签 python xpath screen-scraping scrapy

我正在尝试从该网站抓取目录,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']

Quick Tip: Getting The XPath In Google Chrome.

关于python - 无法获取用于屏幕抓取的 xpath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17129953/

相关文章:

Python 网页抓取 rightmove

python - Pandas,根据多列使用下一个条件值填充单元格

C# 使用 XPATH 选择具有已知值的特定元素,然后删除

python - scrapy xpath 如何

php - PHP DOMXPath-用于选择包含包含具有特定属性的输入的tr的表达式

Python BS4 抓取 : AttributeError: 'NavigableString' object has no attribute 'text'

python - 被 scrapy 困住了,下面是来自 subreddits 的 imgur 链接

python - 在Python中识别列表列表中的峰值海拔

python - 对两个 pandas 列执行逐行操作

python - 如何处理错误引发 - Python3 中的 Asyncio