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插件自动生成
微信扫一扫,打赏作者吧~![[整理]how to run flask with pyqt5](http://www.jyguagua.com/wp-content/themes/begin/timthumb.php?src=http://www.jyguagua.com/wp-content/uploads/2021/03/pyqt_flask.png&w=280&h=210&zc=1)
![[已解决]LINK : fatal error LNK1158: cannot run 'rc.exe' 错误的解决办法](http://www.jyguagua.com/wp-content/themes/begin/timthumb.php?src=http://www.jyguagua.com/wp-content/uploads/2021/02/Snipaste_2021-02-17_15-18-26-1024x505.png&w=280&h=210&zc=1)
![[已解决]Python扩展模块 error: Unable to find vcvarsall.bat](http://www.jyguagua.com/wp-content/themes/begin/timthumb.php?src=http://www.jyguagua.com/wp-content/uploads/2020/11/Snipaste_2020-11-19_10-01-38.png&w=280&h=210&zc=1)
![[整理]PyQt画圆,动态变色](http://www.jyguagua.com/wp-content/themes/begin/timthumb.php?src=http://www.jyguagua.com/wp-content/uploads/2020/08/drawCircle.gif&w=280&h=210&zc=1)