我正在尝试使用xpath从论坛中抓取编辑帖子。我想让蜘蛛实现的功能之一是,当下一页从当前页面中删除时,它将自动转到下一页。页面html代码如下所示:
<span class="next-button"><a href="https://www.reddit.com/r/InteriorDesign/?count=975&after=t3_8ol7yp" rel="nofollow next" >next ›</a></span>
我使用xpath选择器为:response.xpath("//a@class =‘next-按钮’“),但它没有给我任何反馈。有人能帮我找出原因吗?
谢谢!浩
发布于 2018-06-18 13:24:36
@class
属性位于span
元素上,而不是a
链接元素上。所以将您的XPath更改为
response.xpath("//span[@class = 'next-button']/a")
选择a
或
response.xpath("//span[@class = 'next-button']/a/@href")
才能得到链接地址。
https://stackoverflow.com/questions/50917628
复制相似问题