用python从网上下载一个excel文件 [英] downloading an excel file from the web in python

查看:54
本文介绍了用python从网上下载一个excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下网址:

dls = "http://www.muellerindustries.com/uploads/pdf/UW SPD0114.xls"

我尝试下载文件:

urllib2.urlopen(dls, "test.xls")

这生成了一个名为test.xls"的文件,但这显然是一个 html 文件.如果我在 firefox 中打开 html 文件,它会打开一个 excel 文件,但如果我在 excel 中打开文件,它绝对不是我要找的 excel 文件.

This made a file called "test.xls" but this is clearly an html file. If I opened the html file in firefox it opened an excel file, but if I opened the file in excel it was definitely not the excel file I was looking for.

如果我有一个像上面这样的网址,我如何让python将excel文件下载为excel文件?

If I have a web address like the one above, how do I make python download the excel file as an excel file?

推荐答案

这会将 excel 文件保存在运行脚本的同一文件夹中.

This would save the excel file in the same folder that the script was ran from.

import urllib
dls = "http://www.muellerindustries.com/uploads/pdf/UW SPD0114.xls"
urllib.request.urlretrieve(dls, "test.xls")  # For Python 3
# urllib.urlretrieve(dls, "test.xls")  # For Python 2

这篇关于用python从网上下载一个excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆