我正在使用firefox进行selenium+python编程,自动开始下载并保存文件。我已经完成了所有操作,但无法下载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)
我使用了这个,但我没有收到文件,也没有收到任何错误。
任何人请帮助我..
我的文件是![我到达这里,下一步是使用 selenium+python 程序下载它][1]
如果有人有解决方案请帮助我。
这是一个适合我使用 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)