我正在努力找出收到错误的原因:
AttributeError:“ HtmlResponse”对象没有属性“ data”
来自文档:
SplashJsonResponse provide extra features:
response.data attribute contains response data decoded from JSON; you can access it like response.data['html'].
这是我的示例代码:
class HeadphonesSpider(scrapy.Spider):
name = "headphones"
handle_httpstatus_list = [404]
def start_requests(self):
splash_args = {
'html': 1,
'png': 1,
'width': 600,
'render_all': 1,
}
yield SplashRequest('https://domain.tld', self.parse_result, endpoint='render.json', args=splash_args)
def parse_result(self, response):
title = response.css('title').extract_first()
print(title)
png_bytes = base64.b64decode(response.data['png'])
#... rest of the processing
飞溅渲染服务器正在http://0.0.0.0:8050/上运行,当我从控制台发出curl
命令时,我可以从中接收数据。