2014-07-08 48 views
1

如果返回None或请求回调中的空列表 - 将终止刮取。如果我只想忽略此请求并继续处理预定请求,该怎么办?如何从回调中返回空结果并继续刮取?

+0

你有一些示例代码吗? – johntellsall

+0

@shavenwarthog我错了 - 刮被终止,因为蜘蛛试图抓取域不是'allowed_domains'属性的网址。 –

+0

@GillBates - 你有没有考虑过使用Drop Item http://doc.scrapy.org/en/latest/topics/exceptions.html#dropitem? – Girish

回答

0

你有2种选择:

如果你没有使用产量

return 
#or 
return None 

如果你确实使用了屈服

#to interrupt parse function execution 
return 

#to return None for current item and continue parse function execution 
yield None 
# or just do nothing 
0

您需要使用scrapy例外DropItem在处理项目在物品管道中。

检查在Scrapy文档中指定的example。例如,如果需要,可以使用例如以下的方法来制造一种或多种其他材料。来自文档的示例代码示例。

from scrapy.exceptions import DropItem 

class PricePipeline(object): 
    vat_factor = 1.15 

    def process_item(self, item, spider): 
     if item['price']: 
      if item['price_excludes_vat']: 
       item['price'] = item['price'] * self.vat_factor 
       return item 
      else: 
       raise DropItem("Missing price in %s" % item)