使用xlrd从http网站打开Excel [英] Open an excel from http website using xlrd

查看:57
本文介绍了使用xlrd从http网站打开Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Python 3.5.4中使用xlrd从Web打开excel文件.

I trying to open an excel file from web using xlrd, in Python 3.5.4.

import requests
import xlrd
import urllib

link='http://www.bla.com/bla.xlsx'
request = urllib.request.urlretrieve(link) 
workbook = xlrd.open_workbook(request)  

我收到此错误.

TypeError: invalid file: ('0xlxs', <http.client.HTTPMessage object at 0x04600590>)

有人暗示吗?

谢谢!

推荐答案

urlretrieve返回一个元组,而不是url内容.

The urlretrieve returns a tuple, not the url content.

urllib.request.urlretrieve(url,filename = None,reporthook = None,data = None)

urllib.request.urlretrieve(url, filename=None, reporthook=None, data=None)

返回一个元组(文件名,标头),其中filename是可以在其中找到对象的本地文件名,标头是由urlopen()返回的对象的info()方法返回的(对于远程对象)

Returns a tuple (filename, headers) where filename is the local file name under which the object can be found, and headers is whatever the info() method of the object returned by urlopen() returned (for a remote object).

import requests
import xlrd
import urllib

link = 'https://raw.githubusercontent.com/SheetJS/test_files/a9c6bbb161ca45a077779ecbe434d8c5d614ee37/AutoFilter.xls'
file_name, headers = urllib.request.urlretrieve(link)
print (file_name)
workbook = xlrd.open_workbook(file_name)
print (workbook)

这篇关于使用xlrd从http网站打开Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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