python如何获取验证码
怎么获取验证码呢?我也很懵逼
解决思路:将整个注册页面保存下来,定位图片验证码图片的坐标,计算图片四个定点的位置,将图片验证截取;
from PIL import Image # 获取验证码:先将验证码的图片保存下来; # 将注册页面的保存为图片 driver.save_screenshot("./image/register_screenshot.png") # 定位验证码图片的位置,并截取该位置的图片 code_element = driver.find_element_by_id("getcode_num") print(code_element.location) # {'x': 548, 'y': 523} left = code_element.location['x'] top = code_element.location['y'] right = code_element.size['width'] + left height = code_element.size['height'] + top im = Image.open("./image/register_screenshot.png") img = im.crop((left, top, right, height)) img.save("./image/code_num.png")
来源:PY学习网:原文地址:https://www.py.cn/article.html