Python 中的 Selenium Webdriver - Chrome 首选项中的文件下载目录更改 [英] Selenium Webdriver in Python - files download directory change in Chrome preferences
本文介绍了Python 中的 Selenium Webdriver - Chrome 首选项中的文件下载目录更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Selenium Webdriver(在 Python 中)来自动下载数千个文件.我想以编程方式设置 Chrome 的下载文件夹.阅读this后,我尝试了这个:
I'm using Selenium Webdriver (in Python) to automate the downloading of thousands of files. I want to set Chrome's download folder programmatically. After reading this, I tried this:
chromepath = '/Users/thiagomarzagao/Desktop/searchcode/chromedriver'
desired_caps = {'prefs': {'download': {'default_directory': '/Users/thiagomarzagao/Desktop/downloaded_files/'}}}
driver = webdriver.Chrome(executable_path = chromepath, desired_capabilities = desired_caps)
不好.下载仍会转到默认下载文件夹(/Users/thiagomarzagao/Downloads").
No good. Downloads still go to the default download folder ("/Users/thiagomarzagao/Downloads").
有什么想法吗?
(Python 2.7.5、Selenium 2.2.0、Chromedriver 2.1.210398、Mac OS X 10.6.8)
(Python 2.7.5, Selenium 2.2.0, Chromedriver 2.1.210398, Mac OS X 10.6.8)
推荐答案
以下对我有用:
chromeOptions = webdriver.ChromeOptions()
prefs = {"download.default_directory" : "/some/path"}
chromeOptions.add_experimental_option("prefs",prefs)
chromedriver = "path/to/chromedriver.exe"
driver = webdriver.Chrome(executable_path=chromedriver, options=chromeOptions)
来源:https://sites.google.com/a/chromium.org/chromedriver/capabilities
这篇关于Python 中的 Selenium Webdriver - Chrome 首选项中的文件下载目录更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文