The latest Selenium in 2021 really bypasses webdriver detection

I have read a lot of selenium articles, but not many can really be bypassed! The following is a way for everyone to achieve a real bypass through js file injection! Welcome to like and follow one-click triple-link!

1. What is really bypassing browser detection?

  • https://bot.sannysoft.com This is the real detection URL of chrome

  • Why is it important to bypass webdriver attribute detection?

    • Some URLs are detected by webdriver so that Selenium cannot get elements, cannot control buttons, etc.

1. The effect of opening chrome in the PC environment

Insert picture description here
Generally speaking, even if the normal webdriver is enabled, the monogram is red. The above is to open the detection properties of the local chrome

2. Normal start webdriver

  • Upload
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 injection really bypasses the detection attributes of webdriver

Why is my injected js attribute valid?

  • The js file is used in pyppetter to bypass the webdriver detection and is
    now directly imported into the chrome started by Selenium
    I put the key js file at the end of the article
    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]

  • If the naming is not uniform, it is enough to be able to read
  • method of obtaining:
    • Install node.js
    •   npx extract-stealth-evasions
      

A stealth.min.js file will be generated under the folder where you execute the command

I found the modified js file through the everything tool and copied it before using it. At the same time, I also provide a free download method under csdn, because the resources cannot be downloaded directly for free. In order not to cost everyone’s C coins, follow me and become a fan to download Up

Insert picture description here
After the review is approved, I will attach a link to the comment

Guess you like

Origin blog.csdn.net/weixin_38640052/article/details/112692031