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

查看:2022
本文介绍了在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.urlretrieve(dls, "test.xls")

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

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