Mozilla的Selenium简介

时间:2016-12-12 16:30:43

标签: python python-2.7 selenium mozilla

我尝试为Mozilla Firefor创建配置文件,以便在没有对话框的情况下下载csv文件:

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2)
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.download.dir', os.getcwd())
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', ('application/vnd.ms-excel'))

binary = FirefoxBinary(r'C:\Program Files (x86)\Mozilla Firefox\firefox.exe')

driver = webdriver.Firefox(firefox_profile=profile,firefox_binary=binary)

当我到达下载文件时,它会打开对话框,我的个人资料是默认的'。我做错了什么?

1 个答案:

答案 0 :(得分:0)

如果添加

怎么办?
application/csv,text/csv

,即:

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.panel.shown', false)
profile.set_preference('browser.download.folderList', 2)
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.download.dir', os.getcwd())
profile.set_preference('browser.helperApps.neverAsk.openFile', ('application/csv,text/csv,application/vnd.ms-excel,application/x-msexcel,application/excel,application/x-excel,text/comma-separated-values')) 
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', ('application/csv,text/csv,application/vnd.ms-excel,application/x-msexcel,application/excel,application/x-excel,text/comma-separated-values'))
profile.set_preference('browser.download.manager.alertOnEXEOpen', false)
profile.set_preference('browser.download.manager.focusWhenStarting', false)
profile.set_preference('browser.download.manager.useWindow', false)                                                    
profile.set_preference('browser.download.manager.showAlertOnComplete', false)
profile.set_preference('browser.download.manager.closeWhenDone', true)
binary = FirefoxBinary(r'C:\Program Files (x86)\Mozilla Firefox\firefox.exe')

driver = webdriver.Firefox(firefox_profile=profile,firefox_binary=binary)