方法二、使用selenium-stealth 我也没成功,大家可以试试 pip3 install selenium-stealth from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.service import Service from selenium_stealth import stealth options = Options() options.add_argument("start-maximized") # Chrome is controlled by automated test software options.add_experimental_option("excludeSwitches", ["enable-automation"]) options.add_experimental_option('useAutomationExtension', False) s = Service('C:\\BrowserDrivers\\chromedriver.exe') driver = webdriver.Chrome(service=s, options=options) # Selenium Stealth settings stealth(driver, languages=["en-US", "en"], vendor="Google Inc.", platform="Win32", webgl_vendor="Intel Inc.", renderer="Intel Iris OpenGL Engine", fix_hairline=True, )
driver.get("https://bot.sannysoft.com/")
方法三、使用undetected-chromedriver 这个确实成功了~
GitHub - ultrafunkamsterdam/undetected-chromedriver: Custom Selenium Chromedriver | Zero-Config | Passes ALL bot mitigation systems (like Distil / Imperva/ Datadadome / CloudFlare IUAM) pip3 install undetected_chromedriver import undetected_chromedriver as uc driver = uc.Chrome()
driver.get('https://nowsecure.nl')
还有一点要注意: 异常现象: 如果使用pyinstaller对undetected-chromedriver直接进行打包,那打包后的exe大概率无法运行的。 解决方法: 在代码最开始在import 模块之前加上以下内容,然后再进行打包即可: from multiprocessing import freeze_support freeze_support() 原因解析: 在调用某些模块的时候,也是进程,而在多进程中,你程序中的进程不会被阻塞,而一直循环起进程。而undetected-chromedriver内部正好就开了进程。
|