国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

Python超強爬蟲8天速成(完整版)爬取各種網(wǎng)站數(shù)據(jù)實戰(zhàn)案例

2023-03-10 20:22 作者:佛系丨少年  | 我要投稿

P57 12306模擬登陸(滑動驗證)

"""
@Author:lalala
@File:07.12306模擬登陸.py
@Date:2023/03/10
"""
import time
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver import ChromeOptions
# 配置瀏覽器的設置
option = ChromeOptions()
# 規(guī)避selenium被檢測到的風險
option.add_experimental_option('excludeSwitches',['enable-automation'])
option.add_argument('--disable-blink-features=AutomationControlled')
# 定義chrome驅動地址
path = Service('chromedriver.exe')
# 創(chuàng)建瀏覽器操作對象
browser = webdriver.Chrome(service=path,options=option)
# 設置隱式等待時間,5s內找到了元素就繼續(xù)執(zhí)行,找不到報超時(為了防止找元素的時候元素還沒加載出來)
browser.implicitly_wait(5)

# 訪問網(wǎng)站
browser.get('https://kyfw.12306.cn/otn/resources/login.html')
# 定位輸入賬號密碼,點擊登陸
browser.find_element(By.ID, "J-userName").send_keys("xxxx")
browser.find_element(By.ID, "J-password").send_keys("xxxx")
browser.find_element("id", "J-login").click()
# 獲取滑塊和滑塊條
# slider = browser.find_element("class name","nc_iconfont")
slider = browser.find_element(By.XPATH,'//*[@id="nc_1_n1z"]')
slider_length = browser.find_element("class name","nc-lang-cnt")
# print(slider_length.size)
# 創(chuàng)建動作鏈,長按點擊滑塊,拖動滑塊
action = ActionChains(browser)
action.click_and_hold(slider)
action.move_by_offset(slider_length.size['width'], 0).perform()
action.release()
time.sleep(5)
browser.quit()


Python超強爬蟲8天速成(完整版)爬取各種網(wǎng)站數(shù)據(jù)實戰(zhàn)案例的評論 (共 條)

分享到微博請遵守國家法律
商洛市| 同江市| 呼图壁县| 石景山区| 瑞安市| 盐山县| 阳春市| 新乐市| 青冈县| 胶州市| 孟津县| 连州市| 台江县| 新宾| 吉林省| 衢州市| 武夷山市| 凤城市| 花莲市| 丰城市| 福海县| 祁东县| 广灵县| 扬中市| 丽水市| 公主岭市| 南溪县| 璧山县| 冕宁县| 萨嘎县| 成武县| 佛冈县| 吉木乃县| 梅河口市| 开原市| 纳雍县| 民勤县| 富蕴县| 乐亭县| 鹤壁市| 焦作市|