使用scrapy进行无限滚动页面的抓取。

问题描述 投票:0回答:1

我想请大家帮忙搜刮无限滚动的页面。目前,我已经进入了 pageNumber = 100这可以帮助我从100页中获取名称。

但我想爬行所有的页面,直到最后。由于页面有无限滚动,并且是新的scrapy,我无法做到这一点。我在过去的2天里一直在尝试这个方法。

class StorySpider(scrapy.Spider):
    name = 'story-spider'
    start_urls = ['https://www.storytel.com/in/en/categories/3-Crime?pageNumber=100']

    def parse(self, response):
        for quote in response.css('div.gridBookTitle'):
            item = {
                'name': quote.css('a::attr(href)').extract_first()
            }
            yield item

原链接是 https:/www.storytel.cominencategories1-Children. 我看到pageNumber变量在脚本标签里面,如果能帮助找到解决方法。

任何帮助将被感激。先谢谢了!!!!!!!!!!。

python-3.x scrapy web-crawler data-science
1个回答
0
投票

如果你搜索的XPath像 <link rel="next" href=''> 你会发现分页选项。在此帮助下,你可以添加分页代码。

这里是一些分页的例子。

 next_page = xpath of pagination

 if len(next_page) !=0:
       next_page_url = main_url.join(next_page
       yield scrapy.Request(next_page_url, callback=self.parse)

它将帮助你。

© www.soinside.com 2019 - 2024. All rights reserved.