使用Selenium和python将文件下载到指定的位置 [英] Downloading file to specified location with Selenium and python

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

问题描述

到目前为止,我有我的程序去网站我想下载链接和选择它,然后Firefox对话框出现,我不知道该怎么做。我想将此文件保存到我的桌面上的文件夹。我正在使用这个每晚构建,所以我需要这个工作。请帮助。



这是我的代码,从网站上下载链接:

  driver = web driver.Firefox()
driver.implicitly_wait(5)
driver.get(我从中抓取的网站名称)
driver.find_element_by_xpath (// a [contains(text(),'DEV.tgz')]。click()


Firefox自动保存这个特定的文件类型。



这可以通过设置 browser.helperApps.neverAsk.saveToDisk 首选项来实现:

  from selenium import webdriver 
$ b profile = webdriver.FirefoxProfile()
profile.set_preference(browser.download.folderList,2)
profile.set_preference browser.download.manager.showWhenStarting,False)
profile.set_preference(browser.download.dir,'PATH TO DESKTOP')
profile.set_preference(browser.helperApps.neverAsk.saveToDisk ,application / x-gzip)

driver = webdriver.Firefox(firefox_profile = profile)
driver.get(我从中抓取的网站名称)
driver.find_element_by_xpath(// a (包含(text(),'DEV.tgz')])。click()

更多解释:

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