【问题标题】:Scraping infinite scrolling pages using scrapy使用scrapy抓取无限滚动页面
【发布时间】:2020-06-05 10:58:00
【问题描述】:

我在抓取无限滚动页面方面需要帮助。目前,我输入了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.com/in/en/categories/1-Children。我看到 pageNumber 变量在脚本标记内,如果它有助于找到解决方案。

任何帮助将不胜感激。提前致谢!!

【问题讨论】:

    标签: python-3.x scrapy web-crawler data-science


    【解决方案1】:

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

    这是分页页面的一些示例。

     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)
    

    它会帮助你。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-08
      • 2018-04-16
      • 2021-12-10
      • 1970-01-01
      • 2017-01-06
      • 2021-10-02
      • 2020-02-18
      • 1970-01-01
      相关资源
      最近更新 更多