最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python+selenium行為鏈登錄12306(滑動(dòng)驗(yàn)證碼滑塊)

 更新時(shí)間:2022年02月10日 17:12:45   作者:侯小啾??  
這篇文章主要介紹了python+selenium行為鏈登錄12306,使用python網(wǎng)絡(luò)爬蟲登錄12306,下面小編為大家分享一段代碼,具有一定的參考價(jià)值,需要的小伙伴可以參考一下

使用python網(wǎng)絡(luò)爬蟲登錄12306,網(wǎng)站界面如下。因?yàn)榫W(wǎng)站的反爬是不斷升級(jí)的,以下代碼雖然當(dāng)前可用,但早晚必將會(huì)不再能滿足登錄需求。但是知識(shí)的價(jià)值,是不容置疑的。

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import time
from selenium.webdriver import ChromeOptions

# 去除瀏覽器識(shí)別
option = ChromeOptions()
option.add_experimental_option('excludeSwitches', ['enable-automation'])
option.add_experimental_option("detach", True)


driver = webdriver.Chrome(options=option)

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

# 解決特征識(shí)別
script = 'Object.defineProperty(navigator, "webdriver", {get: () => false,});'
driver.execute_script(script)

# 輸入賬號(hào)
driver.find_element_by_id('J-userName').send_keys('123@163.com')

# 輸入密碼
driver.find_element_by_id('J-password').send_keys('xxxxxxx')

# 點(diǎn)擊登陸
driver.find_element_by_id('J-login').click()

# 等待2秒鐘,不要點(diǎn)的太快,以免被識(shí)別或者以免網(wǎng)頁(yè)加載跟不上。
time.sleep(2)

# 滑動(dòng)
# 定位 滑塊標(biāo)簽
span = driver.find_element_by_id('nc_1_n1z')
actions = ActionChains(driver) # 行為鏈實(shí)例化
time.sleep(2) # 等待2秒鐘

# 經(jīng)截圖測(cè)量,滑塊需要滑過的距離為300像素
actions.click_and_hold(span).move_by_offset(300, 0).perform() # 滑動(dòng)

解決瀏覽器識(shí)別:

其中的以下這幾行代碼,可用去除瀏覽器對(duì)selenium的識(shí)別,如圖可以使瀏覽器頁(yè)面不再顯示圖中“Chrome正受到自動(dòng)測(cè)試軟件的控制”字樣。

from selenium.webdriver import ChromeOptions

option = ChromeOptions()
option.add_experimental_option('excludeSwitches', ['enable-automation'])
option.add_experimental_option("detach", True)

driver = webdriver.Chrome(options=option)

解決特征識(shí)別的代碼:

script = 'Object.defineProperty(navigator, "webdriver", {get: () => false,});'
driver.execute_script(script)

如果不采取去除特征識(shí)別,即以下兩行代碼。則頁(yè)面的滑塊驗(yàn)證碼在滑動(dòng)后,會(huì)顯示如下圖的出錯(cuò),從而阻止登錄進(jìn)行。因?yàn)榉?wù)器識(shí)別到的selenium的特征。使用該兩行代碼更改了特征,即可以順利通過識(shí)別。

到此這篇關(guān)于python+selenium行為鏈登錄12306(滑動(dòng)驗(yàn)證碼滑塊)的文章就介紹到這了,更多相關(guān)python+selenium行為鏈登錄12306內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

阳朔县| 铜川市| 大化| 兴仁县| 辽阳县| 辽阳市| 芜湖市| 延津县| 德昌县| 荔浦县| 井冈山市| 防城港市| 尼木县| 永昌县| 科技| 延长县| 南涧| 兴文县| 安吉县| 克什克腾旗| 旅游| 修文县| 松溪县| 保亭| 龙门县| 余姚市| 西藏| 增城市| 海淀区| 聂荣县| 杭锦后旗| 陵水| 南平市| 江孜县| 赤峰市| 韶山市| 宜君县| 开原市| 龙海市| 溆浦县| 万盛区|