我有这个简单的蜘蛛,当我调用scrapy crawl dataspider
它工作正常并在输出中打印项目时:
import json
from scrapy.spiders import Spider
class dataspider(Spider):
name='dataspider'
start_urls=('https://www.google.com/finance/match?matchtype=matchall&ei=UVlPWNmDEYm_U7SqgvAH&q=AAPL',)
def parse(self, response):
j=json.loads( response.body.decode('utf-8') )
yield j['matches'][1]
输出:
{'' AAPL'' n':' Apple Inc.'' e&#39 ;:'纳斯达克',' id':' 22144'}
但是,只要我尝试使用scrapy crawl dataspider -o out.json
将项目保存在文件中,我就会收到此错误:
AttributeError:' FeedExporter'对象没有属性' slot'
回溯是:
2017-01-30 01:10:57 [scrapy.utils.signal] ERROR: Error caught on signal handler: <bound method FeedExporter.close_spider of <scrapy.extensions.feedexport.FeedExporter object at 0x7f31e2d8ab00>>
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/twisted/internet/defer.py", line 150, in maybeDeferred
result = f(*args, **kw)
File "/usr/lib/python3.6/site-packages/pydispatch/robustapply.py", line 55, in robustApply
return receiver(*arguments, **named)
File "/usr/lib/python3.6/site-packages/scrapy/extensions/feedexport.py", line 198, in close_spider
slot = self.slot
AttributeError: 'FeedExporter' object has no attribute 'slot'
在回溯的早期,我也有这个:
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/twisted/internet/defer.py", line 150, in maybeDeferred
result = f(*args, **kw)
File "/usr/lib/python3.6/site-packages/pydispatch/robustapply.py", line 55, in robustApply
return receiver(*arguments, **named)
File "/usr/lib/python3.6/site-packages/scrapy/extensions/feedexport.py", line 187, in open_spider
uri = self.urifmt % self._get_uri_params(spider)
File "/usr/lib/python3.6/site-packages/scrapy/extensions/feedexport.py", line 262, in _get_uri_params
params[k] = getattr(spider, k)
File "/usr/lib/python3.6/site-packages/scrapy/spiders/__init__.py", line 36, in logger
logger = logging.getLogger(self.name)
File "/usr/lib/python3.6/logging/__init__.py", line 1813, in getLogger
return Logger.manager.getLogger(name)
File "/usr/lib/python3.6/logging/__init__.py", line 1167, in getLogger
raise TypeError('A logger name must be a string')
TypeError: A logger name must be a string
知道问题是什么吗?
答案 0 :(得分:0)
我尝试使用管理员权限运行命令,问题已解决。