關於selenium被檢測問題

大多數網站經過檢測瀏覽器參數來進行判斷是否是selenium啓動的瀏覽器,咱們在利用selenium執行某些方法的同時,可能會形成某些參數出現(navigator.webdriver、無頭裏UA出現webdriver),因此寫下這篇隨筆,來儘量地不被網站檢測到。
 
法一:
網站會檢測某個特殊參數$cdc_asdjflasutopfhvcZLmcfl,固然不止這一個,還有許多其他參數
網上有許多人是經過mitmproxy來攔截請求進行修改參數的
import re from mitmproxy import ctx def response(flow): if '/js/yoda.' in flow.request.url: for webdriver_key in ['webdriver', '__driver_evaluate', '__webdriver_evaluate', '__selenium_evaluate', '__fxdriver_evaluate', '__driver_unwrapped', '__webdriver_unwrapped', '__selenium_unwrapped', '__fxdriver_unwrapped', '_Selenium_IDE_Recorder', '_selenium', 'calledSelenium', '_WEBDRIVER_ELEM_CACHE', 'ChromeDriverw', 'driver-evaluate', 'webdriver-evaluate', 'selenium-evaluate', 'webdriverCommand', 'webdriver-evaluate-response', '__webdriverFunc', '__webdriver_script_fn', '__$webdriverAsyncExecutor', '__lastWatirAlert', '__lastWatirConfirm', '__lastWatirPrompt', '$chrome_asyncScriptInfo', '$cdc_asdjflasutopfhvcZLmcfl_' ]: ctx.log.info('Remove "{}" from {}.'.format( webdriver_key, flow.request.url )) flow.response.text = flow.response.text.replace('"{}"'.format(webdriver_key), '"NO-SUCH-ATTR"') flow.response.text = flow.response.text.replace('t.webdriver', 'false') flow.response.text = flow.response.text.replace('ChromeDriver', '')

這個方法說得其實也不錯,有一部分是是經過低版本進行反編譯後的chromedriver,就如Stackflow的答主同樣,進行反編譯低版本的chromdriver,而後配套對應版本的chrome。這兩個版本都各有其中的特色,可是都沒辦法作到繞過全部的檢測。即使開源的selenium,咱們也沒有足夠精力去研究其打開頁面進行操做後修改了哪些參數。python

這裏提供一下進行反編譯後的chromedriver   version: 版本 76.0.3809.100(正式版本) (64 位)web

連接:https://pan.baidu.com/s/1a_rn6mdI4v_ndOwnVRxMHA
提取碼:jkhy chrome


法二,這個可能會繞過更大多數檢測
這個方法原理是利用chrome的debug模式,這個繼承與chrome的配置文件,也就是正常的瀏覽器配置。
首先關閉全部的chrome瀏覽器(重要,看完下面的再關),再cmd到chrome.exe的目錄下(windows通常爲C:\Program Files (x86)\Google\Chrome\Application)執行
chrome.exe --remote-debugging-port=9222
這一條命令是打開一個chrome的debug模式,端口號是9222
而後在咱們調用webdriver時傳入debuggerAddress
from selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() options.add_experimental_option("debuggerAddress", "127.0.0.1:9222") driver = webdriver.Chrome(executable_path='D://chromedriver.exe', options=options) driver.get('https://login.taobao.com')

相關文章
相關標籤/搜索