其他分享
首页 > 其他分享> > 处理12306登录的核心问题

处理12306登录的核心问题

作者:互联网

处理12306登录的核心问题

主要解决问题:

  1. selenium被浏览器识别怎么办
  2. 滑动验证怎么解决

代码:

from selenium.webdriver import Chrome
import time
from selenium.webdriver import ActionChains
from selenium.webdriver.chrome.options import Options

# 如果你的程序被识别到了怎么办
# 浏览器是通过window.navigator.webdriver识别(注意window是小写)
# 解决方式:适用于谷歌浏览器版本>=88的方式
option = Options()
# option.add_experimental_option( 'excludeSwitches',['enable-automation'])
option.add_argument('--disable-blink-features=AutomationControlled')

web = Chrome(options=option)

web.get('https://kyfw.12306.cn/otn/resources/login.html')
web.maximize_window()

web.find_element_by_xpath('/html/body/div[1]/div[2]/div[2]/ul/li[2]/a').click()

# 输入 用户名密码
web.find_element_by_xpath('//*[@id="J-userName"]').send_keys('用户名')
web.find_element_by_xpath('//*[@id="J-password"]').send_keys('密码')
web.find_element_by_xpath('//*[@id="J-login"]').click()

time.sleep(30)

# 处理滑动校验
btn=web.find_element_by_xpath('//*[@id="nc_1_n1z"]')
ActionChains(web).drag_and_drop_by_offset(btn,800,0).perform()


web.quit()

标签:xpath,web,option,登录,核心,selenium,element,12306,find
来源: https://www.cnblogs.com/ngstx/p/15371576.html