簡體   English   中英

firefox中的文件下載對話框

[英]file download dialog in firefox

我使用firefox進行selenium + python編程,自動啟動下載並保存file.i已經做了所有事情,但無法下載csv文件。 我的python版本是2.6.6,我的selenium版本是最新版本。 我嘗試使用以下鏈接(即)

fp = webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList",2)
fp.set_preference("browser.download.manager.showWhenStarting",False)
fp.set_preference("browser.download.dir",getcwd())
fp.set_preference("browser.helperApps.neverAsk.saveToDisk","text/csv")
browser = webdriver.Firefox(firefox_profile=fp)

我用過這個,但我得到了文件,我也沒有發現任何錯誤。 任何一個PLZ幫助我..

我的文件是![我到了這里,我的下一步是使用selenium + python程序下載] [1]

如果任何人有解決方案PLZ幫助我。

這是一個完整的示例,適用於我使用Firefox 3.6.24和8.0.1。

#!/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
from selenium import webdriver

profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.dir',"/tmp/webdriver-downloads")
profile.set_preference('browser.download.folderList',2)
profile.set_preference('browser.helperApps.neverAsk.saveToDisk',"text/csv")
driver = webdriver.Firefox(profile)
base_url = "http://localhost/"
driver.get(base_url + "/text.csv")

您確定您的Web服務器將text / csv作為Mime類型返回嗎? 驗證的一種方法是使用curl確認HTTP響應中的Content-Type標頭是您所期望的:

$ curl -v http://localhost/text.csv
* About to connect() to localhost port 80 (#0)
*   Trying 127.0.0.1... connected
> GET /text.csv HTTP/1.1
> User-Agent: curl/7.23.1 (x86_64-apple-darwin10.8.0) libcurl/7.23.1 OpenSSL/1.0.0e zlib/1.2.5 libidn/1.22
> Host: localhost
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Wed, 28 Dec 2011 17:10:46 GMT
< Server: Apache/2.2.20 (Unix) mod_ssl/2.2.20 OpenSSL/0.9.8r DAV/2
< Last-Modified: Wed, 28 Dec 2011 17:05:47 GMT
< ETag: "291f98-0-4b52a02cbb0c0"
< Accept-Ranges: bytes
< Content-Length: 0
< Cache-Control: max-age=300
< Expires: Wed, 28 Dec 2011 17:15:46 GMT
< Content-Type: text/csv
< 
* Connection #0 to host localhost left intact
* Closing connection #0

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM