第一种,参考青南大佬的:公众号 未闻的code
self.broswer.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", { "source": """ Object.defineProperty(navigator, 'webdriver', { get: () => undefined }) """ })
第二种,可能失效了
# js1 = '''Object.defineProperties(navigator,{ webdriver:{ get: () => false } }) ''' # js2 = '''window.navigator.chrome = { runtime: {}, }; ''' # js3 = '''Object.defineProperty(navigator, 'languages', { get: () => ['en-US', 'en'] }); ''' # js4 = '''Object.defineProperty(navigator, 'plugins', { get: () => [1, 2, 3, 4, 5,6], }); ''' # self.broswer.execute_script(js1) # self.broswer.execute_script(js2) # self.broswer.execute_script(js3) # self.broswer.execute_script(js4)