Python Selenium: Firefox neverAsk.saveToDisk when downloading from Blob URL

早过忘川 提交于 2019-12-11 05:33:20

问题


I wish to have Firefox using selenium for Python to download the Master data (Download, XLSX) Excel file from this Frankfurt stock exchange webpage.

The problem: I can't get Firefox to download the file without asking where to save it first.

Let me first point out that the URL I'm trying to get the Excel file from, is really a Blob URL:

http://www.xetra.com/blob/1193366/b2f210876702b8e08e40b8ecb769a02e/data/All-tradable-ETFs-ETCs-and-ETNs.xlsx

Perhaps the Blob is causing my problem? Or, perhaps the problem is in my MIME handling?

from selenium import webdriver

profile_dir = "path/to/ff_profile"
dl_dir = "path/to/dl/folder"

ff_profile = webdriver.FirefoxProfile(profile_dir)

ff_profile.set_preference("browser.download.folderList", 2)
ff_profile.set_preference("browser.download.manager.showWhenStarting", False)
ff_profile.set_preference("browser.download.dir", dl_dir)
ff_profile.set_preference('browser.helperApps.neverAsk.saveToDisk', "text/plain, application/vnd.ms-excel, text/csv, text/comma-separated-values, application/octet-stream")

driver = webdriver.Firefox(ff_profile)

url = "http://www.xetra.com/xetra-en/instruments/etf-exchange-traded-funds/list-of-tradable-etfs"
driver.get(url)

dl_link = driver.find_element_by_partial_link_text("Master data")
dl_link.click()

回答1:


The actual mime-type to be used in this case is:

application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

How do I know that? Here is what I've done:

  • opened Firefox manually and navigated to the target site
  • when downloading the file, checked the checkbox to save these kind of files automatically
  • went to Help -> Troubleshooting Information and navigated to the "Profile Folder"
  • in the profile folder, foudn and opened mimetypes.rdf
  • inside the mimetypes.rdf found the record/resource corresponding to the excel file I've recently downloaded


来源:https://stackoverflow.com/questions/39519518/python-selenium-firefox-neverask-savetodisk-when-downloading-from-blob-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!