无法使用Selenium Python下载CSV文件

时间:2015-11-18 19:26:18

标签: python selenium

我无法使用Selenium Python下载CSV文件。下载对话框不断弹出,文件无法下载。

以下是我下载的对话框

Dialog Box on downloading

from selenium import webdriver
from BasePage import BasePage
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
from selenium.webdriver.common.keys import Keys
import unittest
from selenium.webdriver.support.select  import Select
import time
from selenium.webdriver.support.ui      import WebDriverWait
import os
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile

fp = webdriver.FirefoxProfile()

fp.set_preference("browser.download.folderList",2)
fp.set_preference("browser.download.manager.showWhenStarting",False)
fp.set_preference("browser.download.dir", os.getcwd())

fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "test/csv")

# fp.set_preference("pdfjs.disabled", True)

browser = webdriver.Firefox(firefox_profile=fp)

1 个答案:

答案 0 :(得分:0)

不是test/csv,而应该是text/csv

如果这不起作用,该文件可能具有不同的mime类型,请尝试以下操作:

fp.set_preference('browser.helperApps.neverAsk.saveToDisk', "text/plain, application/vnd.ms-excel, text/csv, text/comma-separated-values, application/octet-stream")