簡體   English   中英

通過python請求模塊從Web下載數據時如何將文件從excel更改為csv?

[英]How to change the file from excel to csv when download data from web by python request module?

我正在使用python從網頁下載文件,提交請求后,得到的標題如下:

標頭

{'Content-Disposition': 'attachment; filename=SABR_Download.xls', 
'Content-Encoding': 'UTF-8', 'Transfer-Encoding': 'chunked', 'Expires': '0', 'Keep-Alive': 'timeout=5, max=100', 
'Server': 'Apache', 
'Connection': 'Keep-Alive', 
'Pragma': 'no-cache', 
'Cache-Control': 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0', 'Date': 'Wed, 22 Jun 2016 04:21:54 GMT', 
'Content-Type': 'application/excel; charset=UTF-8'}

這是Chrome開發者工具的響應標頭:

響應標題查看源

Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:Keep-Alive
Content-Disposition:attachment; filename=SABR_Download.xls
Content-Encoding:UTF-8
Content-Type:application/excel; charset=UTF-8
Date:Wed, 22 Jun 2016 04:19:53 GMT
Expires:0
Keep-Alive:timeout=5, max=100
Pragma:no-cache
Server:Apache
Transfer-Encoding:chunked

下載文件的默認格式為Excel。 我的問題是如何下載csv格式而不是excel格式的文件。 謝謝。

除非您要從中下載的網站提供了以CSV格式下載的特定URL,否則您將必須下載Excel電子表格並進行解析以獲取您認為合理的數據轉換。

有一個名為xlrd的Python模塊可以幫助您解決這個問題: https : //github.com/python-excel/xlrd

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM