February 2018
Beginner to intermediate
364 pages
10h 32m
English
The following is the code of the WebsiteScreenshotGenerator class:
class WebsiteScreenshotGenerator(): def __init__(self): self._screenshot = None def capture(self, url, width, height, crop=True): print ("Capturing website screenshot of: " + url) driver = webdriver.PhantomJS() if width and height: driver.set_window_size(width, height) # go and get the content at the url driver.get(url) # get the screenshot and make it into a Pillow Image self._screenshot = Image.open(io.BytesIO(driver.get_screenshot_as_png())) print("Got a screenshot with the following dimensions: {0}".format(self._screenshot.size)) if crop: # crop the image self._screenshot = self._screenshot.crop((0,0, width, height)) print("Cropped the image to: {0} {1}"
Read now
Unlock full access