【问题标题】:Next button in scrapyscrapy中的下一个按钮
【发布时间】:2019-10-28 15:28:18
【问题描述】:

我需要在 if 语句中使用 if 语句,我已经必须确定我的抓取程序何时单击下一个按钮,以便一旦发生这种情况我就可以做一些事情。当前的 if 语句只是确定页面上是否有下一步按钮。但我不知道如何确定下一个按钮何时被实际点击。

            # Finds next page button
            priority = response.meta['priority']
            next_page = response.xpath('//a[contains(., "- Next>>")]/@href').get()
            # If it exists and there is a next page enter if statement
            if next_page is not None:
                # Go to next page
                yield response.follow(next_page, self.parse, priority=priority, meta={'priority': priority})

【问题讨论】:

    标签: python web-scraping scrapy splash-screen


    【解决方案1】:

    meta 键中有一个标志来确定该链接是否来自被点击的 NEXT 按钮

    def parse(self, response):
    
        if response.meta.get('isNextClicked', False):
            #Next was clicked
    
        # Finds next page button
        priority = response.meta['priority']    
    
        next_page = response.xpath('//a[contains(., "- Next>>")]/@href').get()
        # If it exists and there is a next page enter if statement
        if next_page is not None:
            # Go to next page
            yield response.follow(next_page, self.parse, priority=priority, meta={'priority': priority, 'isNextClicked': True})
    

    【讨论】:

      猜你喜欢
      • 2013-09-19
      • 2020-11-11
      • 1970-01-01
      • 2022-01-09
      • 1970-01-01
      • 1970-01-01
      • 2016-05-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多