当前位置:网站首页>2021 the latest selenium truly bypasses webdriver detection

2021 the latest selenium truly bypasses webdriver detection

2022-06-21 13:54:00 Programmer hyperspace

If you are little white , This set of information can help you become a big bull , If you have rich development experience , This set of information can help you break through the bottleneck
2022web Full set of video tutorial front-end architecture H5 vue node Applet video + Information + Code + Interview questions .

I've seen a lot selenium article , But not many can really bypass ! Let's pass js File injection is the way to achieve real bypass ! Welcome to like and pay attention to one click three links !

One 、 What is really bypassing browser detection ?

  • https://bot.sannysoft.com This is a chrome The real detection website

  • Why emphasize bypassing webdriver Property detection ?

    • Some web sites through webdriver Detection makes Selenium Cannot get element 、 Unable to control buttons, etc

1、PC Environment on chrome The effect of

 Insert picture description here
Generally speaking, the common enable webdriver Even the logo is red , The above is local chrome Detection properties of

2、 Normal startup webdriver

  • Upper code

    from selenium import webdriver

    class WebDriverChrome(object):

    def __init__(self):
        self.driver = self.StartWebdriver()
    
    def StartWebdriver(self):
        options = webdriver.ChromeOptions()
        options.add_argument("start-maximized")
        options.add_experimental_option("excludeSwitches", ["enable-automation"])
        options.add_experimental_option("useAutomationExtension", False)
        driver = webdriver.Chrome(options=options)
        return driver
    
    def RunStart(self):
        self.driver.get('https://bot.sannysoft.com')
        # time.sleep(10)
        # self.driver.quit()
    

    if name == ‘main’:
    Crawl = WebDriverChrome()
    Crawl.RunStart()

 Insert picture description here

3、Js Inject real bypass webdriver Detection properties of

Why did I inject js Property is valid ?

  • The js File is pyppetter To bypass webdriver The... Used in the test
    Now import directly into Selenium Starting up chrome in
    pivotal js I put the document at the end of the text
    Upper code :

    from selenium import webdriver

    class WebDriverChrome(object):

    def __init__(self):
        self.driver = self.StartWebdriver()
    
    def StartWebdriver(self):
        options = webdriver.ChromeOptions()
        options.add_argument("start-maximized")
        options.add_experimental_option("excludeSwitches", ["enable-automation"])
        options.add_experimental_option("useAutomationExtension", False)
        driver = webdriver.Chrome(options=options)
        with open('./stealth.min.js') as f:
            js = f.read()
        driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
            "source": js
        })
        return driver
    
    def RunStart(self):
        self.driver.get('https://bot.sannysoft.com')
        # time.sleep(10)
        # self.driver.quit()
    

    if name == ‘main’:
    Crawl = WebDriverChrome()
    Crawl.RunStart()

 Insert picture description here

js Injected file [stealth.min.js]

  • The naming is not uniform. It is required to be able to read
  • Access method :
    • install node.js
    •     npx extract-stealth-evasions
      

It will generate a... Under the folder where you execute the command stealth.min.js file

I'm through everything Tools found to change js file , Copy and then use , At the same time, I also provide csdn Download for free , Because resources cannot be downloaded directly for free , In order not to consume everyone's C The coin , Follow me to become a fan and you can download

 Insert picture description here
After the approval , I'll attach a link to the comment

原网站

版权声明
本文为[Programmer hyperspace]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202221431133782.html