51Testing软件测试论坛

标题: 如何使用Selenium工具绕过游览器指纹的方法?(三种) [打印本页]

作者: 草帽路飞UU    时间: 2022-8-25 15:55
标题: 如何使用Selenium工具绕过游览器指纹的方法?(三种)
[attach]141925[/attach]
浏览器指纹的详细解释可以看这个:
https://blog.csdn.net/sxf1061700625/article/details/123967812


方法一、使用stealth.min.js

反正我是没成功,大家仅供参考

def mergeStealthJS(self, browser):

    #https://bot.sannysoft.com /

    if not os.path.exists('stealth.min.js'):

        url = 'https://cdn.jsdelivr.net/gh/requireCool/stealth.min.js/stealth.min.js'

        resp = requests.get(url)

        with open('stealth.min.js', 'w+') as f:

            f.write(resp.text)

    with open('stealth.min.js', 'r') as f:

        content = f.read()

    browser.execute_cdp_cmd('Page.addScriptToEvaluateOnNewDocument', {'source': content})

    return browser





作者: 草帽路飞UU    时间: 2022-8-25 15:59
方法二、使用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内部正好就开了进程。









欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2