模拟登陆12306
.对12306进行模拟登陆.
需使用到超级鹰. 以对超级鹰板块截切。。。
http://www.chaojiying.com/user/mysoft/
import time
from PIL import Image
from base64 import b64decode
from selenium.webdriver import ActionChains
#对12306界面发请求
bro=webdriver.Chrome(executable_path=chromedriver路径')
bro.get('https://kyfw.12306.cn/')
bro.maximize_window()#网页最大化
time.sleep(3)
#点击到账号登陆
#find_elements_by_xpath无法点击
a=bro.find_element_by_xpath('/html/body/div[2]/div[2]/ul/li[2]/a')
a.click()
time.sleep(3)
#对整个界面截图
bro.save_screenshot('screen.png')
#用xpath找到验证码位置 定位图片位置,获取 src 的属性值
#get_attribute(‘src’) 会把换行符替换为"%0A",因此解码的时候要替换回去。
code_img_ele=bro.find_element_by_xpath('//*[@id="J-loginImg"]').get_attribute('src')
code_img_name= code_img_ele.split(",")[-1] # 删除前面的 “data:image/jpeg;base64,”
img_str = code_img_name.replace("%0A", '\n') # 将