selenium 截图

http://blog.csdn.net/u010953692/article/details/78320025

# coding:utf-8
# coding:cp936
from selenium import webdriver
from PIL import Image

broswer = webdriver.Chrome()
broswer.get("http://www.baidu.com")
broswer.save_screenshot(r'E:\photo.png')
baidu = broswer.find_element_by_id('su')
left = baidu.location['x']
top = baidu.location['y']
elementWidth = baidu.location['x'] + baidu.size['width']
elementHeight = baidu.location['y'] + baidu.size['height']
picture = Image.open(r'E:\photo.png')
picture = picture.crop((left, top, elementWidth, elementHeight))
picture.save(r'E:\photo2.png')

  

posted @ 2017-12-14 13:33  xqnq2007  阅读(128)  评论(0编辑  收藏  举报