当前位置:网站首页>使用 Scrapy 框架对重复的 url 无法获取数据,dont_filter=True
使用 Scrapy 框架对重复的 url 无法获取数据,dont_filter=True
2022-08-03 09:26:00 【月亮给我抄代码】
场景:代码没有报错,而且确定 xpath 表达式正确解析。
可能的原因是:你使用了 Scrapy 对重复的 url 进行请求。
Scrapy 内置了重复过滤功能,默认情况下该功能处于打开状态。
如下实例,parse2 无法被调用:
import scrapy
class ExampleSpider(scrapy.Spider):
name ="test"
# allowed_domains = ["https://www.baidu.com/"]
start_urls = ["https://www.baidu.com/"]
def parse(self,response):
yield scrapy.Request(self.start_urls[0],callback=self.parse2)
def parse2(self, response):
print(response.url)
Scrapy 在进入 parse 时,会默认请求一次 start_urls[0],而当你在 parse 中又对 start_urls[0] 进行请求时,Scrapy 底层会默认过滤掉重复的 url,不会对该请求进行提交,这就是为什么 parse2 不被调用的原因。
解决方法:
添加 dont_filter=True 参数,这样 Scrapy 就不会过滤掉重复的请求。
import scrapy
class ExampleSpider(scrapy.Spider):
name ="test"
# allowed_domains = ["https://www.baidu.com/"]
start_urls = ["https://www.baidu.com/"]
def parse(self,response):
yield scrapy.Request(self.start_urls[0],callback=self.parse2,dont_filter=True)
def parse2(self, response):
print(response.url)
此时,parse2 会被正常调用。
边栏推荐
- 基于二次型性能指标的燃料电池过氧比RBF-PID控制
- Batch PNG format can be converted to JPG format
- Flink Yarn Per Job - Submit application
- LINGO 18.0 software installation package download and installation tutorial
- MySQL 主从切换步骤
- milvus
- Laya中关于摄像机跟随人物移动或者点击人物碰撞器触发事件的Demo
- CSP-S2019 Day2
- gpnmb+ gpnmb-AT2 cell idling mapping Epithelial cell idling mapping
- LINGO 18.0软件安装包下载及安装教程
猜你喜欢
索引(三)
STP生成树(端口状态+端口角色+收敛机制 )|||| STP优化技术( uplinkfast技术+Portfast技术+backbonefast技术 )详解
Cartesi 2022 年 7 月回顾
兔起鹘落全端涵盖,Go lang1.18入门精炼教程,由白丁入鸿儒,全平台(Sublime 4)Go lang开发环境搭建EP00
别人都不知道的“好用”网站,让你的效率飞快
Rabbit and Falcon are all covered, Go lang1.18 introductory and refined tutorial, from Bai Ding to Hongru, the whole platform (Sublime 4) Go lang development environment to build EP00
ClickHouse 数据插入、更新与删除操作 SQL
What are pseudo-classes and pseudo-elements?The difference between pseudo-classes and pseudo-elements
手把手教你如何自制目标检测框架(从理论到实现)
Flink Yarn Per Job - Submit application
随机推荐
命令行加载特效 【cli-spinner.js】 实用教程
Laya中关于摄像机跟随人物移动或者点击人物碰撞器触发事件的Demo
【LeetCode】112.路径总和
文章列表的显示 以及创建文章 还有文章详情的基本
10 minutes to get you started chrome (Google) browser plug-in development
Oracle数据库表空间整理回收与释放操作
【字节面试】word2vector输出多少个类别
基于百度AI和QT的景物识别系统
Exception: Dataset not found. Solution
10分钟带你入门chrome(谷歌)浏览器插件开发
二叉查找树的综合应用
LINGO 18.0 software installation package download and installation tutorial
MySQL-存储过程-函数-
Automated test browser driver download version
STP普通生成树安全特性— bpduguard特性 + bpdufilter特性 + guard root 特性 III loopguard技术( 详解+配置)
QT中线程调用GUI主线程控件的问题
ClickHouse删除数据之delete问题详解
mysql8安装步骤教程
scala reduce、reduceLeft 、reduceRight 、fold、foldLeft 、foldRight
英文语法-状语从句