可以自動跳過驗證
from selenium import webdriver
import time
import random
def run():
url_survey = ("https://www.wjx.cn/vm/eJOnwAK.aspx") # 根據需要填寫url
option = webdriver.ChromeOptions()
option.add_experimental_option('excludeSwitches', ['enable-automation'])
option.add_experimental_option('useAutomationExtension', False)
browser = webdriver.Chrome(options=option)
browser.execute_cdp_cmd('Page.addScriptToEvaluateOnNewDocument',
{'source': 'Object.defineProperty(navigator, "webdriver", {get: () => undefined})'})
browser.get(url_survey)
time.sleep(2)
# 1
randomId = random.randint(1, 2)
browser.find_element_by_css_selector("div[for='q1_{}']".format(randomId)).click()
browser.execute_script("window.scrollBy(0,200)") # 模擬滑輪滾動 沒有的話 問題會加載不全
time.sleep(3)
js = "document.getElementById(\"ctlNext\").click()"
browser.execute_script(js)
time.sleep(3)
bn = browser.find_element_by_class_name("mainColor")
bn.click()
time.sleep(3)
# # 再點智能驗證提示框,進行智能驗證
browser.find_element_by_id('rectBottom').click()
time.sleep(6)
browser.quit() #運行完畢自動關閉瀏覽器
if __name__ == "__main__":
while True:
run()
time.sleep(10) #避免提交過快出現驗證
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/340709.html
標籤:其他
上一篇:Appium環境搭建
下一篇:Selenium學習總結
