欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

selenium執(zhí)行js并繞過(guò)webdriver監(jiān)測(cè)常見(jiàn)方法

 更新時(shí)間:2022年04月12日 11:35:07   作者:Jeff的技術(shù)棧  
這篇文章主要為大家介紹了selenium執(zhí)行js并繞過(guò)webdriver監(jiān)測(cè)常見(jiàn)方法,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步早日升職加薪

selenium執(zhí)行js

優(yōu)點(diǎn):直接調(diào)用瀏覽器的環(huán)境
障礙:繞過(guò)selenium監(jiān)測(cè)

原理:

# 執(zhí)行js代碼
bro.execute_script('js代碼')

常見(jiàn)的selenium監(jiān)測(cè)手段

正常登錄 window.navigator.webdriver == undefined
自動(dòng)化的 window.navigator.webdriver == true

除此之外,還有一些其它的標(biāo)志性字符串(不同的瀏覽器可能會(huì)有所不同),常見(jiàn)的特征串如下所示:

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_  

了解了這個(gè)特點(diǎn)之后,就可以在瀏覽器客戶端JS中通過(guò)檢測(cè)這些特征串來(lái)判斷當(dāng)前是否使用了selenium,并將檢測(cè)結(jié)果附加到后續(xù)請(qǐng)求之中,這樣服務(wù)端就能識(shí)別并攔截后續(xù)的請(qǐng)求。

常用繞過(guò)selenium監(jiān)測(cè)1

正常登錄 window.navigator.webdriver == undefined
自動(dòng)化的 window.navigator.webdriver == true

from selenium import webdriver
options = webdriver.ChromeOptions()
# 此步驟很重要,設(shè)置為開(kāi)發(fā)者模式,防止被各大網(wǎng)站識(shí)別出來(lái)使用了Selenium
options.add_experimental_option('excludeSwitches', ['enable-automation'])
#停止加載圖片
options.add_experimental_option("prefs", {"profile.managed_default_content_settings.images": 2})
browser = webdriver.Chrome(options=options)
browser.get('https://www.taobao.com/')

常用繞過(guò)selenium監(jiān)測(cè)2

from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option('debuggerAddress','127.0.0.1:9222')
browser=webdriver.Chrome(executable_path=r'C:\Users\TR\AppData\Local\Google\Chrome
\Application\chromedriver.exe',chrome_options=chrome_options)
browser.get('http://www.zhihu.com')

終端輸入如下指令:chrome.exe --remote-debugging-port=9222 --user-data-dir=“D:\cdsf”(需要谷歌驅(qū)動(dòng)在系統(tǒng)環(huán)境變量下,然后再運(yùn)行程序)

remote-debugging-port是你代碼中指定的端口debuggerAddress;executable_path是你谷歌驅(qū)動(dòng)位置;user-data-dir隨便指定一個(gè)目錄就行

常用繞過(guò)selenium監(jiān)測(cè)3

1.使用chrome的遠(yuǎn)程調(diào)試模式結(jié)合selenium來(lái)遙控chrome進(jìn)行抓取,這樣不會(huì)攜帶指紋信息

步驟:

- 使用調(diào)試模式手工啟動(dòng)chrome,進(jìn)入chrome的安裝路徑,例如chrome裝在 C:\program\google\chrome.exe下
- 進(jìn)入chrome安裝路徑
- 執(zhí)行命令:
#注意端口不要被占用,防火墻要關(guān)閉,user-data-dir用來(lái)指明配置文件的路徑
   chrome.exe --remote-debugging-port=9222 --user-data-dir="指向任意空文件夾"

2.啟動(dòng)完·之后新建python文件

運(yùn)行代碼:

import requests
from selenium import webdriver
chrome_options = "C:\Users\Administrator\AppData\Local\Google\Chrome\Application\chrome.exe"
chrome_options  = webdriver.ChromeOptions()
chrome_options.add_experimental_option('debuggerAddress','10.8.13.95:9222')
browser = webdriver.Chrome(chrome_options=chrome_options)
browser.get("https://www.zhihu.com/signup?next=%2F")
# chrome.exe --remote-debugging-port=9222 --user-data-dir="D:\moni"

這樣監(jiān)測(cè)的就不是selenium模擬了

常用繞過(guò)selenium監(jiān)測(cè)4

def selenium(js):
    option = webdriver.ChromeOptions()
    # option.add_argument('--headless')
    option.add_experimental_option('useAutomationExtension', False)
    option.add_experimental_option('excludeSwitches', ['enable-automation'])
    bro = webdriver.Chrome(executable_path='./chromedriver', options=option)  # 彈出瀏覽器,要給瀏覽器驅(qū)動(dòng)的地址
     # 打開(kāi)頁(yè)面優(yōu)先執(zhí)行的js,execute_cdp_cmd
    bro.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
        "source": """
            Object.defineProperty(navigator, 'webdriver', {
              get: () => undefined
            })
          """
    })
    bro.implicitly_wait(10)
    bro.get('https://www.toutiao.com/')
    time.sleep(5)
    print(bro.page_source)  # 獲取頁(yè)面返回的html代碼
    bro.execute_script(js)
    input()

以上就是selenium執(zhí)行js并繞過(guò)webdriver監(jiān)測(cè)常見(jiàn)方法的詳細(xì)內(nèi)容,更多關(guān)于selenium執(zhí)行js繞過(guò)webdriver監(jiān)測(cè)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • 使用Python判斷IP地址合法性的方法實(shí)例

    使用Python判斷IP地址合法性的方法實(shí)例

    這篇文章主要介紹了使用Python判斷IP地址合法性的方法實(shí)例,需要的朋友可以參考下
    2014-03-03
  • 詳解python數(shù)值與字符串高級(jí)用法

    詳解python數(shù)值與字符串高級(jí)用法

    這篇文章主要介紹了python數(shù)值與字符串高級(jí)用法,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-08-08
  • 使用Python計(jì)算幾何形狀的表面積與體積

    使用Python計(jì)算幾何形狀的表面積與體積

    這篇文章主要給大家介紹了關(guān)于使用Python計(jì)算幾何形狀的表面積與體積的相關(guān)資料,Python可以使用不同的庫(kù)來(lái)進(jìn)行幾何圖形的面積計(jì)算,比如math、numpy、scipy、sympy等,文中給出了詳細(xì)的實(shí)例代碼,需要的朋友可以參考下
    2023-06-06
  • pytorch數(shù)據(jù)預(yù)處理錯(cuò)誤的解決

    pytorch數(shù)據(jù)預(yù)處理錯(cuò)誤的解決

    今天小編就為大家分享一篇pytorch數(shù)據(jù)預(yù)處理錯(cuò)誤的解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-02-02
  • python自動(dòng)腳本的pyautogui入門(mén)學(xué)習(xí)

    python自動(dòng)腳本的pyautogui入門(mén)學(xué)習(xí)

    這篇文章主要介紹了python自動(dòng)腳本的pyautogui入門(mén)學(xué)習(xí),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-04-04
  • 如何用python 操作zookeeper

    如何用python 操作zookeeper

    這篇文章主要介紹了如何用python 操作zookeeper,幫助大家更好的理解和使用python,感興趣的朋友可以了解下
    2020-12-12
  • 使用Python自定義創(chuàng)建的Log日志模塊

    使用Python自定義創(chuàng)建的Log日志模塊

    這篇文章主要介紹了使用Python自定義創(chuàng)建的Log日志模塊,日志文件是用于記錄系統(tǒng)操作事件的文件集合,可分為事件日志和消息日志。具有處理歷史數(shù)據(jù)、診斷問(wèn)題的追蹤以及理解系統(tǒng)的活動(dòng)等重要作用,需要的朋友可以參考下
    2023-07-07
  • 使用PYTHON解析Wireshark的PCAP文件方法

    使用PYTHON解析Wireshark的PCAP文件方法

    今天小編就為大家分享一篇使用PYTHON解析Wireshark的PCAP文件方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-07-07
  • python中multiprosessing模塊的Pool類中的apply函數(shù)和apply_async函數(shù)的區(qū)別

    python中multiprosessing模塊的Pool類中的apply函數(shù)和apply_async函數(shù)的區(qū)別

    這篇文章主要介紹了python中multiprosessing模塊的Pool類中的apply函數(shù)和apply_async函數(shù)的區(qū)別、文章圍繞主題的相關(guān)內(nèi)容展開(kāi)詳細(xì)介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-06-06
  • python 禁止函數(shù)修改列表的實(shí)現(xiàn)方法

    python 禁止函數(shù)修改列表的實(shí)現(xiàn)方法

    下面小編就為大家?guī)?lái)一篇python 禁止函數(shù)修改列表的實(shí)現(xiàn)方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-08-08

最新評(píng)論