scrapy中,当进入到parse函数中,假如有条件不满足,希望爬虫跳过此次解析,如下代码是有错误的:
if info.startswith('Foo'): item['foo'] = info.split(':')[1] else: return None
Scrapy中spider不允许返回None,如果返回None,将会报错:
exceptions.TypeError: You cannot return an "NoneType" object from a spider
正确的做法:
parse(response): #make some manipulations if info.startswith('Foo'): item['foo'] = info.split(':')[1] return [item] else: return []
或者什么也不做:
parse(response): #make some manipulations if info.startswith('Foo'): item['foo'] = info.split(':')[1] yield item else: return
文章的脚注信息由WordPress的wp-posturl插件自动生成