您的位置:首页 > Web前端 > JavaScript

Scrapyjs Splash KeyError 'splash'

2016-05-18 23:02 281 查看
在爬虫中使用了
response.meta['splash']['args']['url']
的方法来获取原始的请求的url,在本地运行时一切正常,但是一部署到服务器上面就出现
KeyError 'splash'
这样的错误。通过在爬虫中加上日志,记录下response.meta中的内容:
logger.info("response.meta: %s", response.meta)
,可以在日志中看到:

[mycustomlogger] INFO: response.meta: {'download_timeout': 180.0, 'source': u'163', '_splash_processed': {'endpoint': 'render.html', 'args': {'images': 0, 'url': 'http://sports.163.com/special/00051K89/nbatpklm.html'}}, 'title': u'\u56fe\u5e93', 'download_latency': 0.3358449935913086, 'depth': 1, 'download_slot': 'sports.163.com'}


可以看出这里的键是
_splash_processed
而不是
splash
,所以修改为
response.meta['_splash_processed']['args']['url']
程序就运行正常了,不过原因还是未知。

唯一不同的是在服务器上时设置中
SPLASH_URL = 'http://localhost:8050/'
,而在本地时写的是公网地址。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: