我试图通过selenium的点击功能自动下载一些链接,我使用chrome webdriver和python作为编程语言.如何通过python程序选择下载目录,以便它不会下载到默认的Downloads目录中.我找到了firefox的解决方案,但每次点击链接时都会弹出下载对话框,这在Chrome中不会发生.
我一整天都在寻找这个,似乎目前没有针对python的chromedriver实现提供的解决方案.
如何使用webdriver.Chrome()方法设置特定的chrome.prefs(例如profile.managed_default_content_settings.images = 2等配置文件设置)?
我已经通过webdriver.ChromeOptions()尝试了它,但没有成功.在Java中,有适当的功能可用于实现此目的.
但是Python?这就是我目前所做的......
options = webdriver.ChromeOptions()
options.add_argument('--allow-running-insecure-content')
options.add_argument('--disable-web-security')
options.add_argument('--disk-cache-dir=/var/www/cake2.2.4/app/tmp/cache/selenium-chrome-cache')
options.add_argument('--no-referrers')
options.add_argument('--window-size=1003,719')
options.add_argument('--proxy-server=localhost:8118')
options.add_argument("'chrome.prefs': {'profile.managed_default_content_settings.images': 2}")
self.selenium = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver',chrome_options=options)
Run Code Online (Sandbox Code Playgroud) 我一直在使用 chrome 浏览器使用 Selenium Java WebDriver,到目前为止取得了相当大的成功。我已经能够启动 chrome 窗口并很好地发送和接收数据。我现在需要找出 Firefox 浏览器的以下配置文件设置的 chrome 等效项。
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "image/jpg");
profile.setPreference("browser.download.dir", "path/to/downloads/pics/folder");
Run Code Online (Sandbox Code Playgroud)
计划做这样的事情(参考:https: //sites.google.com/a/chromium.org/chromedriver/capability),但需要如上所述设置其他属性。
ChromeOptions chromeOptions = new ChromeOptions();
//set the rest of the preferences for chrome as shown above for Firefox
Run Code Online (Sandbox Code Playgroud)
谢谢。
我正在尝试批量下载BlackBoard环境中的大量文件(在世界各地的大学/学校中使用很多).我能够检索文件所在的链接但是一个市长问题:
当文件是.pdf文件时,它将显示在新的浏览器选项卡中,而不是下载.对于例如.xlsx文件下载单击()工作正常..
我可以更改驱动程序设置以更改此行为吗?如何?
编辑
我更新了问题,以回应Ari的回答.它现在包含有关实际插件的更多信息.也许这可用于识别必须禁用的插件..
Chrome PDF Viewer (2 files)
Name: Chrome PDF Viewer
Version:
Location: chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/
Type: BROWSER PLUGIN
Disable
MIME types: MIME type Description File extensions
application/pdf .pdf
Name: Chrome PDF Viewer
Description: Portable Document Format
Version:
Location: internal-pdf-viewer
Type: PPAPI (out-of-process)
Disable
MIME types: MIME type Description File extensions
application/x-google-chrome-pdf Portable Document Format
.pdf
Run Code Online (Sandbox Code Playgroud)