Scrapy Splash Screenshots?

后端 未结 1 702
后悔当初
后悔当初 2020-12-14 23:51

I\'m trying to scrape a site whilst taking a screenshot of every page. So far, I have managed to piece together the following code:

import json
import base64         


        
相关标签:
1条回答
  • 2020-12-15 00:49

    You are decoding from base64 twice:

           png_bytes = base64.b64decode(response.data['png'])
           imgdata = base64.b64decode(png_bytes)
    

    Simply do:

        def parse_result(self, response):
            imgdata = base64.b64decode(response.data['png'])
            filename = 'some_image.png'
            with open(filename, 'wb') as f:
                f.write(imgdata)
    
    0 讨论(0)
提交回复
热议问题