如何在空网页停止 Xpath 分页循环?
How to stop Xpath pagination loop at empty webpage?
我构建了一个抓取某个网站的蜘蛛,它运行良好,我使用了 scrapy。蜘蛛抓取了所有我想抓取的 430 个网页,按照 'next page' 分页 link。问题是 site/scraper 也指向第 431 页,这是空的。等等。因此,刮板不会停止刮!
在所有相关的 430 个页面都被抓取后,任何人都可以帮助我停止网络抓取吗?最后一个相关页面中的 html 代码是:
我的代码是:
next_page = response.xpath('//a[@id="nextWebshopsPage"]').attrib['href']
if next_page is not None:
yield response.follow(next_page, callback=self.parse)
您需要在谓词中指定按钮 不应被禁用:
'//a[@id="nextWebshopsPage" and not(@disabled)]'
我构建了一个抓取某个网站的蜘蛛,它运行良好,我使用了 scrapy。蜘蛛抓取了所有我想抓取的 430 个网页,按照 'next page' 分页 link。问题是 site/scraper 也指向第 431 页,这是空的。等等。因此,刮板不会停止刮!
在所有相关的 430 个页面都被抓取后,任何人都可以帮助我停止网络抓取吗?最后一个相关页面中的 html 代码是:
我的代码是:
next_page = response.xpath('//a[@id="nextWebshopsPage"]').attrib['href']
if next_page is not None:
yield response.follow(next_page, callback=self.parse)
您需要在谓词中指定按钮 不应被禁用:
'//a[@id="nextWebshopsPage" and not(@disabled)]'