我想检查是否在Scrapy项目中设置了字段。但我在项目上使用has_key
,我收到此错误:
Traceback (most recent call last):
File "d:\python27\lib\site-packages\twisted\internet\defer.py", line 653, in _runCallbacks
current.result = callback(current.result, *args, **kw)
File "D:\Kerja\HIT\Python Projects\<project_name>\<project_name>\<project_name>\pipelines.py", line 16, in process_item
self.listing_process.process_new_or_update(item)
File "D:\Kerja\HIT\Python Projects\<project_name>\<project_name>\<project_name>\processor.py", line 290, in process_new_or_update
listing = self.listing_check.normalize_for_process(listing)
File "D:\Kerja\HIT\Python Projects\<project_name>\<project_name>\<project_name>\processor.py", line 213, in normalize_for_process
if listing.has_key('description'):
File "d:\python27\lib\site-packages\scrapy\item.py", line 74, in __getattr__
raise AttributeError(name)
AttributeError: has_key
如何在不使用has_key的情况下检查字段是否已设置?
答案 0 :(得分:1)
'field' in item
代替item.has_key('field')
。