首页 > 解决方案 > 如何获得 Scrapy 请求以转到网站的最后一页?

问题描述

我只需要发出 Scrapy 请求来请求网站的最后一页。

我无法创建进入最后一页的抓取请求。我已经尝试了下面的代码。

last_page = response.css('li.next a::attr(href)').get()
        if next_page is None:
            yield scrapy.Request(last_page, callback=self.parse)

预计爬虫会直接进入最后一页,然后我会从那里做一些操作

标签: python-3.xxpath

解决方案


我相信要走的路是检查源代码以找到“下一页”页面链接并在解析中使用此函数:

current_page = #current_page_link
next_page = #scraping the link using a css selector
if next_page is None:
    yield response.follow(current_page, callback = self.manipulation)


def manipulation(self, response):
    #your code here

推荐阅读