yield scrapy.Request()无效的几种情况

scrapy错误:yield scrapy.Request()不执行、失效、Filtered offsite request to错误。首先我们在Request()方法里面添加这么一个东东:

yield Request(url, callback=self.parse_item, dont_filter=True)

如果发现成功执行,那你就得检查一下你的:allowed_domains,看看前面是不是添加了:http://  ,如(错误写法):

 allowed_domains = ["http://www.baidu.com"]

正确写法:

allowed_domains = ["www.baidu.com"]

去掉之后,把dont_filter=True也去掉,也能正常执行,其实这里是allowed_domains和去重出现了冲突,scrapy allowed_domains判断不严谨产生的问题,所以书写allowed_domains的时候一定不要加:http://

 

其次 yield必须出现在response的方法内部 即必须成对使用

      def parse_link_street(self, response):
                    yield scrapy.Request(
                        url='‘’
                        meta=‘’,
                        callback=‘’,
                        dont_filter=True
                    )
而不能出现如下情况

  def parse_link_street(self):
                    yield scrapy.Request(
                        url='‘’
                        meta=‘’,
                        callback=‘’,
                        dont_filter=True
                    )
 

你可能感兴趣的:(Python,scrapy,spider,python)