使用python在selenium中自动下载firefox

时间:2018-05-28 09:42:31

标签: python selenium firefox webdriver download-manager

我想在点击特定链接时自动下载该文件。但是,这里弹出窗口要求打开并保存选项在selenium中使用firefox浏览器打开。

from selenium import webdriver

profile = webdriver.FirefoxProfile()

profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.download.manager.showWhenStarting", False)
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/text"+",application/pdf"+",txt/csv/xls"+",text/plain")
profile.set_preference("browser.helperApps.neverAsk.openFile", "application/text"+",application/pdf"+",txt/csv/xls"+"text/plain" )
profile.set_preference("browser.download.dir", tempDir)
url = "http://www.seleniumeasy.com/test/generate-file-to-download-demo.html" #sample website
driver = webdriver.Firefox(executable_path= firefox_path, firefox_profile=profile)
driver.get(url)

inpbox = driver.find_element_by_id("textbox")
inpbox.send_keys("Lorem Ipsum \r\n")
driver.find_element_by_id("create").click()
import time
time.sleep(2)
driver.find_element_by_id("link-to-download").click()

这里我正在研究Python 3.6和Firefox 60.0.1版本。

0 个答案:

没有答案