龙空技术网

Python-UI自动化之设置自动化浏览器webdriver属性为false

温水青蛙202306 133

前言:

此时大家对“python浏览器控制”可能比较珍视,咱们都需要了解一些“python浏览器控制”的相关资讯。那么小编在网络上网罗了一些关于“python浏览器控制””的相关内容,希望朋友们能喜欢,同学们一起来学习一下吧!

20230827星期日:

import timefrom selenium import webdriverfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.common.action_chains import ActionChains# window.navigator.webdriver# 自动化的浏览器,为true# 正常的浏览器,为false,# 所以可以设置一下:# 方法如下,两种方法:# 方法一:chrome版本小于88:'''driver_path = "D:\chromedriver\chromedriver-win64\chromedriver.exe"options = webdriver.ChromeOptions()options.add_experimental_option("excludeSwitches",["enable-automation"])driver = webdriver.Chrome(options=options,executable_path=driver_path)driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument",{    "source":"""    navigator.webdriver = undefined      Object.defineProperty(navigator,'webdriver',{        get:() => undefined    })    """})driver.get(";)driver.maximize_window()time.sleep(2)'''# 方法二:chrome版本大于88:# driver_path = "D:\chromedriver\chromedriver-win64\chromedriver.exe"# options = webdriver.ChromeOptions()# options.add_experimental_option("excludeSwitches",["enable-automation"])# driver = webdriver.Chrome(options=options,executable_path=driver_path)driver_path = "D:\chromedriver\chromedriver-win64\chromedriver.exe"options = webdriver.ChromeOptions()options.add_experimental_option("excludeSwitches",["enable-automation"])options.add_argument('--disable-blink-features=AutomationControlled')driver = webdriver.Chrome(options=options)driver.get(";)driver.maximize_window()time.sleep(2)

标签: #python浏览器控制