分享一下验证码识别登录注册脚本 获取验证码图片时,验证码图片位置容易出现问题,截图位置容易出错
# 验证码id标签
code_element = driver.find_element_by_id("getcode_num")
print(code_element.location) # {'x': 551, 'y': 525} 定位验证码坐标
left = int(code_element.location['x']+200)
top = int(code_element.location['y']+130)
# right =code_element.size['width'] + left
right = int(code_element.location['x'] + code_element.size['width']+220)
# height = code_element.size['height'] + top
height = int(code_element.location['y'] + code_element.size['height'] + 145)
# 保存图片
im = Image.open("截图路径\test2.png")
# 图片裁剪
# 获取位置 左、上、右、下
img = im.crop((left, top, right, height))
img.save("截图路径\test3.png")
请看代码 导入相关包
import time
import random
from PIL import Image
from selenium import webdriver
from ShowapiRequest import S
|