# 12306模拟登录编码流程 # 1、使用selenium打开登录页面 2、对当前selenium打开的这张页面进行截图 3、对当前图片局部区域(验证码图片)进行裁剪 (好处:将验证码图片和模拟登录进行一一对应) # 4、使用超级鹰识别验证码图片(坐标) from selenium import webdriver import time from selenium.webdriver import ActionChains from PIL import Image bro=webdriver.Chrome('./chromedriver.exe') bro.get('https://kyfw.12306.cn/otn/login/init') time.sleep(1) bro.save_screenshot('aa.png') # 对页面进行截图 save_screenshot() code_img=bro.find_element_by_xpath('//*[@id="loginForm"]/div/ul[2]') location=code_img.location size=code_img.size # 确定验证码图片左上角和右下角坐标 rangle=(int(location['x']),int(location['y']),int(location['x'])+size['width'],int(location['y']+size['height'])) # 至此验证码区域就确定下来 i=Image.open('aa.png') code_img_name='./code.png' frame=i.crop(rangle) frame.save(code_img_name) # 将验证码交给超级鹰 进行识别 ch
python——利用selenium实现12306模拟登录
最新推荐文章于 2024-04-08 07:21:39 发布