报错 Filtered offsite request
用scrapy框架迭代爬取时报错
scrapy日志:
在 setting.py 文件中 设置 日志 记录等级
LOG_LEVEL= 'DEBUG' LOG_FILE ='log.txt'
观察 scrapy 日志
2017-08-15 21:58:05 [scrapy.spidermiddlewares.offsite] DEBUG: Filtered offsite request to 'sou.zhaopin.com': <GET http://sou.zhaopin.com/jobs/searchresult.ashx?jl=%E4%B8%8A%E6%B5%B7&kw=python&sm=0&source=0&p=2>
2017-08-15 21:58:05 [scrapy.core.engine] INFO: Closing spider (finished)
2017-08-15 21:58:05 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 782,
'downloader/request_count': 3,
'downloader/request_method_count/GET': 3,
'downloader/response_bytes': 58273,
'downloader/response_count': 3,
'downloader/response_status_count/200': 2,
'downloader/response_status_count/302': 1,
'finish_reason': 'finished',
'finish_time': datetime.datetime(2017, 8, 15, 13, 58, 5, 915565),
'item_scraped_count': 59,
'log_count/DEBUG': 64,
'log_count/INFO': 7,
'memusage/max': 52699136,
'memusage/startup': 52699136,
'offsite/domains': 1,
'offsite/filtered': 1,
'request_depth_max': 1,
'response_received_count': 2,
'scheduler/dequeued': 1,
'scheduler/dequeued/memory': 1,
'scheduler/enqueued': 1,
'scheduler/enqueued/memory': 1,
'start_time': datetime.datetime(2017, 8, 15, 13, 58, 5, 98357)}
2017-08-15 21:58:05 [scrapy.core.engine] INFO: Spider closed (finished)
重要的是第一行,我开始做的时候没有意识到这竟然是一个错误,应该是被记录的一个错误提示,然后程序也就没有报错
2017-08-15 21:58:05 [scrapy.spidermiddlewares.offsite] DEBUG: Filtered offsite request to 'sou.zhaopin.com': <GET http://sou.zhaopin.com/jobs/searchresult.ashx?jl=%E4%B8%8A%E6%B5%B7&kw=python&sm=0&source=0&p=2>
DEBUG: Filtered offsite request to
因为 Request中请求的 URL 和 allowed_domains 中定义的域名冲突,所以将Request中请求的URL过滤掉了,无法请求
name = 'zhilianspider'
allowed_domains = ['http://sou.zhaopin.com'] page = 1
url = 'http://sou.zhaopin.com/jobs/searchresult.ashx?jl=%E4%B8%8A%E6%B5%B7&kw=python&sm=0&source=0&p='
start_urls = [url+str(page)]
在 Request 请求参数中,设置 dont_filter = True ,Request 中请求的 URL 将不通过 allowed_domains 过滤。
if self.page <= 10:
self.page +=1
yield scrapy.Request(self.url+str(self.page),callback=self.parse,dont_filter = True)
由于关掉了allowed_domains 过滤,所以要将yield 写在判断条件呢,开始我写在了外面程序一直迭代,停不下来了,尴尬。
之前都是写在if同级下的,那时候还没有关掉过滤所以没问题
网友评论:
SPIDER_MIDDLEWARES = {
'scrapy.spidermiddlewares.offsite.OffsiteMiddleware': None,
}
设置一下这个貌似也是剋的
链接:https://www.jianshu.com/p/c31e53fd45f6
來源:简书
报错 Filtered offsite request的更多相关文章
- scrapy 爬网站 显示 Filtered offsite request to 错误
爬取zol 网站图片,无法抓取. 在 setting.py 文件中 设置 日志 记录等级 LOG_LEVEL= 'DEBUG' LOG_FILE ='log.txt' 查看日志 发现报 2015-11 ...
- 网页中嵌入百度地图报错:The request has been blocked,the content must served over Https
网页中嵌入百度地图 1.进入百度地图开发平台:http://lbsyun.baidu.com/index.php?title=jspopular 2.获取密钥:http://lbsyun.baidu. ...
- scrapy-yield scrapy.Request()不执行、失效、Filtered offsite request to错误 [转]
scrapy错误:yield scrapy.Request()不执行.失效.Filtered offsite request to错误.首先我们在Request()方法里面添加这么一个东东: yiel ...
- svn报错 400 Bad Request
MyEclipse中的svn,commit经常报错 Error: Commit failed (details follow): Error: At least one property chang ...
- [Linux]Centos git报错fatal: HTTP request failed
在使用git pull.git push.git clone会报类似例如以下的错误: error: The requested URL returned error: 401 Unauthorized ...
- SpringBoot整合升级Spring Security 报错 【The request was rejected because the URL was not normalized】
前言 最近LZ给项目框架升级, 从Spring1.x升级到Spring2.x, 在这里就不多赘述两个版本之间的区别以及升级的原因. 关于升级过程中踩的坑,在其他博文中会做比较详细的记录,以便给读者参考 ...
- 【linux】【git】git报错fatal: HTTP request failed
在使用git pull.git push.git clone会报类似如下的错误: error: The requested URL returned error: 401 Unauthorized w ...
- centos git clone 报错 fatal: HTTP request failed 解决办法
git clone报错提示 git clone https://github.com/xxxx.git Initialized empty Git repository in /root/xxxx/. ...
- 小程序运行报错:errMsg: "request:fail url not in domain list"
错误原因: 报错提示说请求的url不在域名列表里,应该是还没有配置服务器域名 解决方法: 可点击开发者工具右上角 详情-项目设置-不校验合法域名.web-view(业务域名).TLS 版本以及 HTT ...
随机推荐
- [转]C# 安装时弹出设置服务登录窗口
本文转自:http://blog.csdn.net/prince_jun/article/details/38435887 安装服务时系统不要弹出设置服务登录窗口:在程序中将serviceProces ...
- [MVC]多文件、超大文件上传
话不多说,上代码. <script src="http://code.jquery.com/jquery-2.1.4.min.js"></script> & ...
- C#同步、异步编程
同步编程public partial class Form1 : Form { public Form1() { InitializeComponent(); } //同步执行 private voi ...
- 1、类、封装(私有private、this关键字)
类与对象 对象在需求中的使用 对面向对象有了了解之后,我们来说说在具体问题中如何使用面向对象去分析问题,和如何使用面向对象. 我们把大象装冰箱为例进行分析. 在针对具体的需求,可以使用名词 ...
- Bash on windows从14.0升级到ubuntu16.04
升级参考:https://www.zhihu.com/question/49411626 解决中文乱码问题参考:http://www.lofter.com/tag/ubuntu%E5%AD%90%E7 ...
- csu 1365 双向链表模拟超时
1365: Play with Chain Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 21 Solved: 5[Submit][Status][W ...
- 记录LNMP环境彻底删除绑定域名及网站文件夹/文件的过程
lnmp vhost del #删除绑定的域名 chattr -i /home/wwwroot/域名文件夹/.user.ini #解除文件安全限制 rm -rf /home/wwwroot/域名文件夹 ...
- SSM Controller 页面之间跳转 重定向,有参 无参问题
需求:spring MVC框架controller间跳转,需重定向.有几种情况:不带参数跳转,带参数拼接url形式跳转,带参数不拼接参数跳转,页面也能显示. (1)我在后台一个controller跳转 ...
- 对WebSocket技术的学习与探索(一)
WebSocket 简要介绍 WebSocket protocol 是HTML5一种新的协议. 它实现了浏览器与服务器全双工通信(full-duple). 一开始的握手需要借助HTTP请求完成. We ...
- Mac系统查看端口占用和杀死进程
查看进程占用 lsof -i tcp:8080 该命令会显示占用8080端口的进程,有其 pid ,可以通过pid关掉该进程 杀死进程 kill pid 例如 kill 39394 转自:https: ...