selenium被識別的解決方法


遇到問題:

selenium做爬蟲能解決很多反爬問題,但是selenium也有很多特征可以被識別,比如用selenium驅動瀏覽器后window.navigator.webdriver值是true,而正常運行瀏覽器該值是未定義的(undefined)

3步解決方案,實測有效

第一步,使用chrome開發者模式

options = webdriver.ChromeOptions() options.add_experimental_option('excludeSwitches', ['enable-automation']) 
  • 1
  • 2

第二步,禁用啟用Blink運行時的功能

options.add_argument("--disable-blink-features=AutomationControlled") 
  • 1

第三步,Selenium執行cdp命令

再次覆蓋window.navigator.webdriver的值

driver = webdriver.Chrome(options=options) driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", { "source": """ Object.defineProperty(navigator, 'webdriver', { get: () => undefined }) """ })
 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM