python-3.x - 如何获得 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)
预计爬虫会直接进入最后一页,然后我会从那里做一些操作
解决方案
我相信要走的路是检查源代码以找到“下一页”页面链接并在解析中使用此函数:
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
推荐阅读
- haskell - How to undestand functors in the Nix expression language?
- cassandra - Cassandra - 如何使用复合键更新记录
- javascript - 使用javascript删除基于列中重复值的HTML表格行元素?
- sql - 在 SQL 中添加列,其中每行取决于其他行中的值
- sql - 如何使用聚合函数进行 GROUP BY CASE
- python - 如何打印大型 XML 的第一行?
- linux - 将非顺序文件移动到新目录
- arrays - 动态 JSON 格式问题
- angular5 - ExpressionChangedAfterItHasBeenCheckedError:表达式在检查后已更改。以前的值:'未定义'。当前值: ''
- android - 如何通过指定语言环境从 UserDictionary 中删除单词?