<p>备注:</p> <ul> <li>测试不必定成功(图像识别技术...),屡次尝试</li> <li>驱动:Chrome驱动</li> <li>图片识别:百度AI提供(APP_ID、API_KEY、SECRET_KEY均由百度AI产生)</li> <li>图像识别过程会在本地保存验证码图片</li> <li>测试网站:<a href="https://pythonav.com/login/">https://pythonav.com/login/</a></li> </ul> ```python import time from selenium import webdriver from aip import AipOcrpython
def initial(): """ 初始化链接 """ APP_ID = '16611607' API_KEY = 'wAIXfXOUS8ztLa4FrK3rZex1' SECRET_KEY = '3b8nvjSGUZq0LPC18VVAizKYRBbny6Mq' return AipOcr(APP_ID, API_KEY, SECRET_KEY)web
def get_file_content(filePath): """ 读取图片 """ with open(filePath, 'rb') as f: return f.read()测试
def selnium_msg(): driver = webdriver.Chrome() try: driver.get('https://pythonav.com/login/') time.sleep(1)网站
# 输入用户名/密码 driver.find_element_by_id('id_username').send_keys('用户名') time.sleep(2) driver.find_element_by_id('id_password').send_keys('密码') time.sleep(2) # 验证码识别 image = driver.find_element_by_id('image_code') file_path = 'a.png' image.screenshot(file_path) # 百度ai相关 client = initial() image = get_file_content(file_path) res = client.basicGeneral(image) # 调用通用文字识别, 图片参数为本地图片 # res2 = client.basicAccurate(image) # 调用通用文字识别(高精度版) driver.find_element_by_id('id_code').send_keys(res['words_result'][0]['words']) driver.find_element_by_class_name('btn-primary').click() time.sleep(3) except Exception as e: print(e) finally: driver.quit()
if name == 'main': selnium_msg()ui