0
点赞
收藏
分享

微信扫一扫

Selenium绕过浏览器指纹的三种方法

飞空之羽 2022-05-03 阅读 98

浏览器指纹的详细解释可以看这个:

常见的浏览器指纹包含哪些_小锋学长生活大爆炸的博客-CSDN博客icon-default.png?t=M3K6https://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

方法二、使用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')

举报

相关推荐

0 条评论