【发布时间】:2019-07-29 00:55:49
【问题描述】:
我正在为该网站创建一个抓取工具: https://www.oddsportal.com/darts/europe/european-championship/results/
我正在使用 splash 插件来渲染 javascript
我想跟踪前几年来获取历史数据,前一年有“非活动”类。所以,我想要一个 Xpath 表达式,它可以找到“活动”年份并获得前一年的 href。
这是 HTML 的 sn-p:
<div class="main-menu2 main-menu-gray"><ul class="main-filter"><li><span class="active"><strong><a href="/darts/europe/european-championship/results/">2018</a></strong></span></li><li><span class="inactive"><strong><a href="/darts/europe/european-championship-2017/results/">2017</a></strong></span></li><li><span class="inactive"><strong><a href="/darts/europe/european-championship-2016/results/">2016</a></strong></span>
这是我的尝试:
response.xpath('//div[@class="main-menu2 main-menu-gray"]/ul/following-sibling::li[child::span[@class="active"]]/strong/a/@href').get()
我希望这会返回:
/darts/europe/european-championship-2017/results/
因为这是当前网址的前一年。
【问题讨论】:
标签: python xpath scrapy scrapy-splash