基于python的-PIL定位截图

2023-01-31 01:01:18 python
# -*- coding:utf-8 -*-
from selenium import WEBdriver
from selenium.webdriver.support.ui import WebDriverWait

# 安装PIL包
# pip install pillow
from PIL import Image

driver = webdriver.Firefox()
driver.get('/file/imgs/upload/202301/31/fdtvmzkvr0q')
# 通过location定位x,y
left = ele.location['x']
top = ele.location['y']
# 通过x,y的值拼接长和宽
right = left + ele.size['width']
bottom = top + ele.size['height']
# 创建img对象
# open()第一个参数 fp:filepath 文件路径
# 打开刚截取的全屏图
img = Image.open('big.png')
# 定位到需要截取的地方
img = img.crop((left, top, right, bottom))
# 截取成功并保存到本地
img.save('captcha.png')

相关文章