Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 具有Scrapy中项目的\u密钥_Python_Python 2.7_Web Scraping_Scrapy_Scrapy Item - Fatal编程技术网

Python 具有Scrapy中项目的\u密钥

Python 具有Scrapy中项目的\u密钥,python,python-2.7,web-scraping,scrapy,scrapy-item,Python,Python 2.7,Web Scraping,Scrapy,Scrapy Item,我想检查一个字段是否设置在一个刮擦项目中。但是我在项目上使用了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:\Ker

我想检查一个字段是否设置在一个刮擦项目中。但是我在项目上使用了
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
回溯(最近一次呼叫最后一次):
文件“d:\python27\lib\site packages\twisted\internet\defer.py”,第653行,在runCallbacks中
current.result=回调(current.result,*args,**kw)
文件“D:\Kerja\HIT\Python Projects\\\\pipelines.py”,第16行,进程中项目
self.listing\u process.process\u new\u或\u update(项目)
文件“D:\Kerja\HIT\Python Projects\\\\processor.py”,第290行,正在处理中\u新建\u或\u更新
listing=self.listing\u check.normalize\u for\u进程(listing)
文件“D:\Kerja\HIT\Python Projects\\\\processor.py”,第213行,在normalize\u for\u进程中
如果清单.has_key('description'):
文件“d:\python27\lib\site packages\scrapy\item.py”,第74行,在\uuu getattr中__
提升属性错误(名称)
AttributeError:具有\u键

如何在不使用has_键的情况下检查字段是否已设置?

终于找到了它。事实证明,即使我们可以在Python2.x上使用Scrapy,它也希望我们使用Python3模式。我应该在item中使用
'field',而不是
item.has_key('field')