使用Chrome驱动程序通过python和selenium下载指定位置的文件 [英] Downloading a file at a specified location through python and selenium using Chrome driver

查看:38
本文介绍了使用Chrome驱动程序通过python和selenium下载指定位置的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 selenium 的点击功能自动下载一些链接,并且我使用 chrome webdriver 和 python 作为编程语言.如何通过python程序选择下载目录,使其不会下载到默认的下载目录中.我找到了 firefox 的解决方案,但每次点击 Chrome 中不会发生的链接时,下载对话框都会不断弹出.

I am trying to automatically download some links through selenium's click functionality and I am using a chrome webdriver and python as the programming language. How can I select the download directory through the python program so that it does not get downloaded in the default Downloads directory. I found a solution for firefox but there the download dialog keeps popping up every time it clicks on the link which does not happen in Chrome.

推荐答案

2018 年更新:

它不是有效的 Chrome 命令行开关,请参阅 源代码使用下面的hoju answer设置首选项.

Its not valid Chrome command line switch, see the source code use hoju answer below to set the Preferences.

原文:

您可以为 chrome 创建配置文件并定义测试的下载位置.下面是一个例子:

You can create a profile for chrome and define the download location for the tests. Here is an example:

from selenium import webdriver

options = webdriver.ChromeOptions() 
options.add_argument("download.default_directory=C:/Downloads")

driver = webdriver.Chrome(chrome_options=options)

这篇关于使用Chrome驱动程序通过python和selenium下载指定位置的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆