scrapy - Request 中的回调函数不执行
2017-07-19 23:57
197 查看
推荐我的个人博客 http://blog.wuzhenyu.com.cn
在 scrapy 中,
调试的时候,发现回调函数
再次查看手册中关于
两种方法能够使 requests 不被过滤:
1. 在
2. 在 scrapy.Request() 函数中将参数
如下摘自手册
在 scrapy 中,
scrapy.Request(url, headers=self.header, callback=self.parse_detail)
调试的时候,发现回调函数
parse_detail没有被调用,这可能就是被过滤掉了,查看 scrapy 的输出日志
offsite/filtered会显示过滤的数目。这个问题如何解决呢,查看手册发现(https://doc.scrapy.org/en/latest/faq.html?highlight=offsite%2Ffiltered)这个问题,这些日志信息都是由 scrapy 中的一个 middleware 抛出的,如果没有自定义,那么这个 middleware 就是默认的
Offsite Spider Middleware,它的目的就是过滤掉那些不在
allowed_domains列表中的请求 requests。
再次查看手册中关于
OffsiteMiddleware的部分(https://doc.scrapy.org/en/latest/topics/spider-middleware.html#scrapy.spidermiddlewares.offsite.OffsiteMiddleware)
两种方法能够使 requests 不被过滤:
1. 在
allowed_domains中加入 url
2. 在 scrapy.Request() 函数中将参数
dont_filter=True设置为 True
如下摘自手册
If the spider doesn’t define an allowed_domains attribute, or the attribute is empty, the offsite middleware will allow all requests. If the request has the dont_filter attribute set, the offsite middleware will allow the request even if its domain is not listed in allowed domains.
相关文章推荐
- scrapy - Request 中的回调函数不执行
- scrapy - Request 中的回调函数不执行
- scrapy - Request 中的回调函数不执行
- wx.request的fail回调函数执行两次的问题
- getJSON回调函数不执行问题?
- jquery ajax提交 回调函数无法执行
- 使用call_user_func_array()来回调执行函数与直接使用函数的区别是什么? 周梦康周梦康 839 2014年04月15日 提问 · 2014年04月15日 更新 关注 0 关注 收藏
- 使用 call_user_func_array() 来回调执行函数和直接调用函数的区别是什么?
- ajax回调函数执行顺序带来的同步异步问题
- JS - 闭包,回调,立即执行函数表达式简单实现
- android显示view时各回调函数执行顺序
- 如何按照顺序执行异步ajax的回调函数
- ASIHttpRequest的requestFinish代理函数到底在什么线程执行
- JQuery中的回调函数不被执行问题的原因
- jQuery中ajax方法无法执行回调函数问题
- 【编程笔记】jquery中的ajax的回调函数不能执行
- jQuery.getJSON( url [, data ] [, success ] ) 中的回调函数参数不执行
- 查看回调函数执行在那个线程中的方法
- android 6.0权限,onRequestPermissionsResult回调不执行
- ajax异步执行回调函数内容