问题
I'm strugling to find out why I receive error:
AttributeError: 'HtmlResponse' object has no attribute 'data'
From documentation:
SplashJsonResponse provide extra features:
response.data attribute contains response data decoded from JSON; you can access it like response.data['html'].
Here is my sample code:
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
Splash rendering server is running on http://0.0.0.0:8050/ and I can receive data from it when I issue curl
command from console.
来源:https://stackoverflow.com/questions/59011139/splashrequest-cannot-get-data-attribute