February 2018
Beginner to intermediate
364 pages
10h 32m
English
The following is the code of this WebsiteScreenshotGenerator:
class WebsiteScreenshotGenerator: def __init__(self, apikey): self._screenshot = None self._apikey = apikey def capture(self, url, width, height, crop=True): key = self.beginCapture(url, "{0}x{1}".format(width, height), "true", "firefox", "true") print("The image key is: " + key) timeout = 30 tCounter = 0 tCountIncr = 3 while True: result = self.tryRetrieve(key) if result["success"]: print("Saving screenshot to: downloaded_screenshot.png" + key) bytes=result["bytes"] self._screenshot = Image.open(io.BytesIO(bytes)) if crop: # crop the image self._screenshot = self._screenshot.crop((0, 0, width, height)) print("Cropped the image to: {0} {1}".format(width, height))
Read now
Unlock full access