After chrome was upgraded to chrome88, selenium modified window.navigator.webdriver

Write in front

Insert picture description here
Google released Chrome88 (big update) in the stable version on January 19, 2021

  • Improved dark theme for Windows 10 and less intrusive permission tips
  • No longer supports FTP URL, Flash, Mac OS X Yosemite
  • Less intrusive permission request
  • All old browser plugins are disabled
  • Digital Goods API: Web applications published in the Google Play Store can now use Play Store billing like local applications.
  • WebXR: AR lighting estimation: For AR and VR content on Android, lighting estimation can help make the model feel more natural and make it more "suitable" for the user's environment.
  • Anchor target = _blank means rel = noopener by default: in order to defend against "tag eavesdropping" attacks, the target's anchor _blank behaves like rel is set to noopener.
  • CSS Aspect-ratio property: This allows the aspect ratio to be explicitly specified for any element to achieve similar behavior to the replaced element.
    Source isolation: Web applications can choose to improve the security of the page in exchange for giving up access to certain APIs.
  • JavaScript engine: Chrome 88 integrates version 8.8 of the V8 JavaScript engine.

More update information can be searched by yourself

The main thing I want to write today is that the selenium crawler data automatic collection code that I have been using has become invalid due to the update to chrome88. This is the second time that my code has failed because of the browser update. In line with the principle of recording my work, I have been This aspect is being continuously updated, so many friends come to ask me this question. If you don’t understand, you can click on the link below to go directly to the previous article. 【chrome88导致无法修改window.navigator.webdriver】Friends who are specifically for the solution can just read this article directly.

1. The sycm data automation that died before the start of the job
2. The problem of modifying the code of window.navigator.webdriver
3. (New) The problem of modifying the code of window.navigator.webdriver

Problem finding

Version Information
Insert picture description here

The main reason why the code cannot be used is the same as before:

  • window.navigator.webdriver value is true

After a few days of investigation, the main reason is

Chrome88 integrates version 8.8 of the V8 JavaScript engine, which causes the original js code to modify the attribute to fail

# 原先修改window.navigator.webdriver的js代码块
 Object.defineProperty(navigator, 'webdriver', {
    
    
          get: () => undefined
        })

Insert picture description here

Error translation: Unable to use defineproperty function to redefine webdriver properties

solution

I’m not too familiar with js. I plan to redefine window.navigator.webdriver with a new js method. After a few days of hard work, I didn’t succeed. Other friends can try this direction. There are good ways to communicate in the comment area.

The final solution:
start with selenium and use --disable-blink-features=AutomationControlledparameters to remove perfectlywindow.navigator.webdriver

#手动登录
def login(extension_path,tmp_path):
    chrome_options = webdriver.ChromeOptions()
    # 设置好应用扩展
    chrome_options.add_extension(extension_path)
    
     #添加下载路径
    prefs = {
    
    'profile.default_content_settings.popups': 0, 'download.default_directory':tmp_path,
             "profile.default_content_setting_values.automatic_downloads":1}#允许多个文件下载
    chrome_options.add_experimental_option('prefs', prefs)

    #修改windows.navigator.webdriver,防机器人识别机制,selenium自动登陆判别机制
    chrome_options.add_experimental_option('excludeSwitches', ['enable-automation']) 
    
    chrome_options.add_argument("--disable-blink-features=AutomationControlled")
#     drive = webdriver.Chrome(chrome_options=chrome_options)
    drive = webdriver.Chrome(options=chrome_options)
    url = 'https://sycm.taobao.com/portal/home.htm'
    drive.implicitly_wait(10)
    drive.get(url)
    input("请手动登录,成功后输入【1】:")
    #叉掉页面无关元素后再输入1继续执行
    drive.maximize_window() #窗口最大化
    tm=random.uniform(1,2)
    time.sleep(tm)
    return drive

Successful test, perfect modification, successful login!
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_35866846/article/details/113185737