Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python中下载文件时如何更改存储路径_Python_Python 3.x_Selenium Webdriver_Selenium Chromedriver - Fatal编程技术网

在Python中下载文件时如何更改存储路径

在Python中下载文件时如何更改存储路径,python,python-3.x,selenium-webdriver,selenium-chromedriver,Python,Python 3.x,Selenium Webdriver,Selenium Chromedriver,我使用SeleniumWebDriver(chrome)在Python中下载了一个.Zip文件,但我无法更改下载目录。我尝试过使用各种开放源码,但都保存在“下载”文件夹中,这是默认路径。你能告诉我更改下载路径的代码吗?下面的代码是最近测试的代码 options = webdriver.ChromeOptions() options.add_argument("download.default_directory=mypath") browser = webdriver.Ch

我使用SeleniumWebDriver(chrome)在Python中下载了一个.Zip文件,但我无法更改下载目录。我尝试过使用各种开放源码,但都保存在“下载”文件夹中,这是默认路径。你能告诉我更改下载路径的代码吗?下面的代码是最近测试的代码

options = webdriver.ChromeOptions() 
options.add_argument("download.default_directory=mypath")
browser = webdriver.Chrome(chrome_options=options)

我一直在用这个方法,可能有更好的方法。 在prefs中添加下载目录作为“添加选项”的参数

options = Options()
#options.add_argument("--headless")
options.add_argument("start-maximized") 
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
prefs = {"profile.default_content_settings.popups": 0,
                 "download.default_directory": r"C:\PROJECT\my_folder\\", #DOWNLOAD DIRECTORY
                 "directory_upgrade": True}
options.add_experimental_option("prefs", prefs)

browser = webdriver.Chrome(executable_path=r'C:/PROJECT/chromedriver.exe', options = options)