Reading an Excel object retrieved using urllib2

穿精又带淫゛_ 提交于 2019-12-04 03:49:19

问题


I am getting an Excel file using urllib2 and saving into response below. I want to be able to process this excel file using xlrd or similar. I included some info below, let me know if I can provide more info. How can I have response object transformed into an object I can play with?

response = <addinfourl at 199999998 whose fp = <socket._fileobject object at 0x100001010>>

response.read() prints: '\xd0\xcf\x11\xe0...'

Headers:
Content-Type: application/vnd.ms-excel
Transfer-Encoding: chunked

回答1:


Using xlrd, and based on its API documentation, it appears like you can use something similar to this:

book = xlrd.open_workbook(file_contents=response.read())

It doesn't appear to support reading a file object (which, IMO, would be ideal), only taking in a filename itself or the above file_contents method.

If file_contents didn't exist or didn't work, you'd have to use tempfile to write the response to a temporary file and read that.



来源:https://stackoverflow.com/questions/13807451/reading-an-excel-object-retrieved-using-urllib2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!