from selenium import webdriver
# 加启动配置
option = webdriver.ChromeOptions()
option.add_experimental_option('useAutomationExtension', False)
option.add_experimental_option('excludeSwitches', ['enable-automation'])
# 打开chrome浏览器
driver = webdriver.Chrome(chrome_options=option)
driver.get("https://www.baidu.com")1、浏览器有界面情况下设置下载路径
def selenium_driver(enact): “”” 驱动浏览器无头模式设置 “”” options = Options() # options.add_argument(‘–headless’) # options.add_argument(‘–no-sandbox’) # options.add_argument(‘–disable-dev-shm-usage’) # 下载路径设置 path = os.path.join(PATH, enact) is_exists = os.path.exists(path) if not is_exists: os.mkdir(path) prefs = {“download.default_directory”: path} options.add_experimental_option(“prefs”, prefs) driver = webdriver.Chrome(executable_path=r”谷歌驱动插件路径”, chrome_options=options) return driver 2、目前不支持无头模式下更改浏览器下载路径,后续可能会支持!