如何从Xpath中的javascript事件处理程序获取链接?

2024-04-24 06:07:14 发布

您现在位置:Python中文网/ 问答频道 /正文

下面给出了Html代码片段。我想要一些响应.xpath(……)获取分页链接。我试过了

 response.xpath('//*[@class="ui2-pagination-pages"]/a/@href').extract()   

但它什么也没给。我做错什么了?谢谢。你知道吗

<div class="ui2-pagination-pages">
         <a href="javascript:void(0)" class="prev" data-role="prev">Prev</a>
        <a rel="nofollow" href="//www.alibaba.com/showroom/acrylic-wine-box_1.html">1</a>
         <a rel="nofollow" href="//www.alibaba.com/showroom/acrylic-wine-box_2.html">2</a>
        <a rel="nofollow" href="//www.alibaba.com/showroom/acrylic-wine-box_3.html">3</a>
        <span class="current">4</span>
         <a rel="nofollow" href="//www.alibaba.com/showroom/acrylic-wine-box_5.html">5</a>
         <a rel="nofollow" href="//www.alibaba.com/showroom/acrylic-wine-<span class="interim">...</span>
        <a rel="nofollow" href="//www.alibaba.com/showroom/acrylic-wine-box_103.html">103</a>
        <a href="javascript:void(0)" class="next" data-role="next">Next</a>
        </div>

我想取消所有分页的链接,并希望通过它循环。我该怎么做?你知道吗


Tags: combox链接htmlwwwxpathclassrel
1条回答
网友
1楼 · 发布于 2024-04-24 06:07:14

这个问题之所以会发生,是因为你要抓取的网站使用Javascript来呈现内容,基本上蜘蛛不能执行Javascript代码他们没有真正能够解释它的引擎,为此ScrapingHub团队创建了一个名为scrapy splash的插件。你知道吗

您可以从他们的官方github页面查看:Github

相关问题 更多 >