就是和云打码相似的验证码识别网站,可是他能识别更复杂的图片验证码html
主要思路web
1.首先登录到12306界面chrome
2.点击帐号密码登陆,到帐号密码登陆模块app
3.截取整张界面的图片保存到本地,并获取验证码部分的坐标网站
4.在界面截图的基础上,根据获取的坐标截取验证码的图片保存到本地ui
5.把图片交给超级鹰,返回结果url
6.把结果解析成想要点击的坐标code
7.输入帐号密码,执行验证码点击,点击登陆orm
8.ok,可是有概率没法识别验证码htm
from selenium import webdriver import chaojiying as cj import time #动做链,点击验证码 from selenium.webdriver import ActionChains #图片处理,截图用 from PIL import Image #实现规避检测 from selenium.webdriver import ChromeOptions #12306登陆url url="https://kyfw.12306.cn/otn/resources/login.html" #规避检测 option = ChromeOptions() option.add_experimental_option('excludeSwitches', ['enable-automation']) chrome=webdriver.Chrome(executable_path="chromedriver",options=option) chrome.maximize_window() #发起请求 chrome.get(url) time.sleep(3) #切换到帐号密码登陆 #找到切换按钮 button=chrome.find_element_by_xpath('/html/body/div[2]/div[2]/ul/li[2]/a') #点击切换到帐号密码登陆 button.click() time.sleep(5) #获取验证码图片的标签对象 code_img=chrome.find_element_by_xpath('//*[@id="J-loginImg"]') #获取验证码图片的左上角x,y坐标位置 img_location=code_img.location #获取验证码图片的长宽 img_size=code_img.size #图片左上角和右下角的坐标 rangle=( int(img_location['x']), int(img_location['y']),int(img_location['x'] + img_size['width']),int(img_location['y'] + img_size['height']) ) time.sleep(2) #截取整张界面的图片 chrome.save_screenshot("12306.png") html_img=Image.open("12306.png") time.sleep(2) #设置截图后的名字 code_img_name="code.png" #截取验证码部分的图片 frame=html_img.crop(rangle) #保存验证码截图 frame.save(code_img_name) time.sleep(2) #将图片发给超级鹰识别获取结果,zx为封装的接口 result=cj.zx() #解决返回结果,建立点击列表 all_location=[] if '|' in result['pic_str']: lo_list=result['pic_str'].split('|') for i in lo_list: lo_list=[] x=int(i.split(',')[0]) y=int(i.split(',')[1]) lo_list.append(x) lo_list.append(y) all_location.append(lo_list) else: lo_list = [] x=int(result['pic_str'][0]) y=int(result['pic_str'][1]) lo_list.append(x) lo_list.append(y) all_location.append(lo_list) for i in all_location: x=i[0] y=i[1] ActionChains(chrome).move_to_element_with_offset(code_img,x,y).click().perform() time.sleep(1) #输入帐号 chrome.find_element_by_id('J-userName').send_keys("******") #输入密码 chrome.find_element_by_id('J-password').send_keys('******') time.sleep(2) #点击登陆 chrome.find_element_by_id('J-login').click() time.sleep(10) chrome.quit()