here is a method of using selenium to get the screenshot and the elements location, then PIL to crop it via its location and size to get just the element and crop out the rest
So here i am trying to extract the google image via a full screenshot...
So here i am trying to extract the google image via a full screenshot...
from selenium import webdriver from PIL import Image FILENAME = ' screenshot.png' driver = webdriver.PhantomJS('/home/metulburr/phantomjs'); driver.set_window_size(1920,1080) driver.get('http://google.com') element = driver.find_element_by_tag_name('img') location = element.location size = element.size driver.save_screenshot(FILENAME) driver.quit() im = Image.open(FILENAME) left = int(location['x']) top = int(location['y']) right = int(location['x'] + size['width']) bottom = int(location['y'] + size['height']) im = im.crop((left, top, right, bottom)) im.save(FILENAME)screenshot.png
Recommended Tutorials: