Created
August 6, 2015 16:46
-
-
Save rekhubs/5bf57815a7e265fb97b4 to your computer and use it in GitHub Desktop.
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 time | |
from PIL import Image | |
from selenium import webdriver | |
from selenium.webdriver.common.keys import Keys | |
# using default firefox profile | |
# selenium looks for user.js rather than prefs.js | |
# defaultProfileDir = "C:\\Users\\rek\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\dsqsvpe2.default"; | |
# profile = webdriver.FirefoxProfile(defaultProfileDir) | |
# driver = webdriver.Firefox(profile) | |
# driver = webdriver.Chrome() | |
driver = webdriver.Firefox() | |
# open a site, screenshot | |
driver.get('http://www.seemh.com/comic/17832/191888.html#p=21') | |
# get pic addr | |
picEle = driver.find_element_by_id('mangaFile') | |
print type(picEle), '\n', picEle | |
addr = picEle.get_attribute('src') | |
print addr | |
# crop image with PIL | |
driver.get_screenshot_as_file('D:\\whole_page_screenshot.png') | |
location = picEle.location | |
print location | |
size = picEle.size | |
print size | |
im = Image.open('D:\\whole_page_screenshot.png') | |
left = location['x'] | |
top = location['y'] | |
right = location['x'] + size['width'] | |
bottom = location['y'] + size['height'] | |
im = im.crop((left, top, right, bottom)) # defines crop points | |
im.save('D:\\selenium-pic-crop.png') # saves new cropped image | |
time.sleep(5) | |
# driver.quit() | |
driver.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment