Last active
November 23, 2019 14:27
-
-
Save Chestermozhao/049388198feb17713cff714d374510f6 to your computer and use it in GitHub Desktop.
scrapy_splash screenshot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import json | |
import base64 | |
from scrapy.spiders import Spider | |
from scrapy_splash import SplashRequest | |
from items import SplashTestItem | |
class SplashSpider(Spider): | |
name = "splash_screen_shot" | |
start_urls = ["https://www.livescore.bet3000.com/"] | |
def start_requests(self): | |
splash_args = { | |
'wait': 6, | |
'html': 1, | |
'png': 1 | |
} | |
for url in self.start_urls: | |
yield SplashRequest(url, self.parse, endpoint='render.json', args=splash_args) | |
def parse(self, response): | |
png_bytes = base64.b64decode(response.data['png']) | |
filename = 'test_image.png' | |
with open(filename, 'wb') as f: | |
f.write(png_bytes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment