如何使用Chrome浏览器自动将文件下载到指定路径
更新:HHH   时间:2023-1-7


小编给大家分享一下如何使用Chrome浏览器自动将文件下载到指定路径,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

#encoding=utf-8
import unittest
from selenium import webdriver
import time
from selenium.webdriver.chrome.options import Options

class TestChromeDownload(unittest.TestCase):

def setUp(self):
    # 创建Chrome浏览器配置对象实例
    options = Options()
    options.add_experimental_option("prefs",{
         "download.default_directory" : r"d:\download",
         "download.prompt_for_download" : False,
         "download.directory_upgrade" : True,
         "safebrowsing.enabled" : True
    })

    # 启动带有自定义设置的Chrome浏览器
    self.driver = webdriver.Chrome(executable_path = "d:\\chromedriver",\
                                   chrome_options = options)

def test_downloadFileByChrome(self):

    url = "http://mirrors.hust.edu.cn/apache/zzz/mirror-tests/"
    self.driver.get(url)
    self.driver.find_element_by_partial_link_text("tar.gz").click()

    time.sleep(20)

if name == "main":
unittest.main()

以上是“如何使用Chrome浏览器自动将文件下载到指定路径”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注天达云行业资讯频道!

返回编程语言教程...