python selenium 定位截图实例

其实也没有什么好解释的,原理就是在 截全屏图之后, 再次二度截取图片
找到元素定位的图片位置, 下面的代码复制粘贴即可

# from selenium import webdriver
# import time
# driver = webdriver.Chrome()
# driver.get('https://www.baidu.com/')
# time.sleep(3)
# driver.save_screenshot('screenshot.png')
# driver.quit()
# broswer.save_screenshot(r'photo.png')

# baidu = broswer.find_element_by_id('su')
# print(baidu)
# 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'photo.png')
# picture = picture.crop((left, top, elementWidth, elementHeight))
# picture.save(r'photo2.png')
# broswer.quit()

猜你喜欢

转载自blog.csdn.net/chang995196962/article/details/84579545