selenium处理12306登录

selenium处理12306登录

使用edge浏览器驱动

from selenium.webdriver import Edge
from selenium.webdriver.common.action_chains import ActionChains  # 事件链
from selenium.webdriver.edge.options import Options
from selenium.webdriver.common.by import By
import time

option = Options()
option.add_argument('--disable-blink-features=AutomationControlled')

web = Edge(executable_path=r'C:\Program Files (x86)\Microsoft\Edge\Application\msedgedriver.exe',options=option)
web.get("https://kyfw.12306.cn/otn/resources/login.html")
time.sleep(2)

# 输入信息登录,账号密码
web.find_element(By.XPATH,r'//*[@id="J-userName"]').send_keys("******")
web.find_element(By.XPATH,'//*[@id="J-password"]').send_keys("******")
time.sleep(2)

# 点击登录
web.find_element(By.XPATH,r'//*[@id="J-login"]').click()
time.sleep(2)

# 拖拽验证
btn=web.find_element(By.XPATH,r'//*[@id="nc_1_n1z"]')
ActionChains(web).drag_and_drop_by_offset(btn,320,0).perform()

time.sleep(2)

运行就ok了
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_46085748/article/details/128202187