xpath无法识别标签

时间:2018-06-18 21:20:00

标签: javascript html xpath web-scraping scrapy

我正在尝试使用xpath从论坛中抓取reddit帖子。 我希望蜘蛛实现的功能之一是在完成从当前页面的报废后立即自动转到下一页。 页面html代码如下所示:

<span class="next-button"><a href="https://www.reddit.com/r/InteriorDesign/?count=975&amp;after=t3_8ol7yp" rel="nofollow next" >next &rsaquo;</a></span>

我使用xpath选择器:        response.xpath(“// a [@class ='next-button']”) 但它没有给我任何回报。有人可以帮我找出原因吗?

谢谢! 郝

1 个答案:

答案 0 :(得分:1)

@class属性位于span元素上,而不是a链接元素。所以将XPath更改为

response.xpath("//span[@class = 'next-button']/a")

选择a

response.xpath("//span[@class = 'next-button']/a/@href")

获取链接地址。

相关问题