python - 使用 xlrd 从 http 网站打开 Excel

标签 python excel xlrd

我尝试在 Python 3.5.4 中使用 xlrd 从网络打开 Excel 文件。

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 内容。

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

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)

关于python - 使用 xlrd 从 http 网站打开 Excel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46437357/

相关文章:

python - 暗网重量训练 'Assertion ' 0' failed'

excel - 从单元格中提取具有特定结构的数字

python - IOError : [Errno 2] No such file or directory on Mac

python - Pandas xlrd 引擎传递了静态值错误

python - 导入错误:无法导入名称 open_workbook

python - 有没有一种简单的方法可以将列表的元素相互映射?

python - 使用 BS4 从网页中提取多个不带 'a' 或 'href' 标签的 URL

python - 使用 Python 将文件上传到 Google Docs 时出现 403 错误

vba - 枢轴和运行时错误 1004 : Application-defined or object-defined error

vba - 选择一系列单元格,并为这些单元格序列偏离的每个数字插入一个空白行