SplashRequest - Cannot get data attribute

痴心易碎 提交于 2020-01-05 08:28:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!