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

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

问题描述

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

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

  from selenium import webdriver 

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

driver = webdriver.Chrome(chrome_options = options)


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.

解决方案

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天全站免登陆