python - pandas html格式的excel文件
问题描述
网页上下载的excel文件,用记事本打开显示如下:
用pandas.read_excel读取的话,提示
XLRDError: Unsupported format, or corrupt file: Expected BOF record; found b’<html x’
假如用excel打开再另存为excel,读取当然可以,但是有很多excel文件这样处理就很繁琐,有没有什么方法么
VBS处理代码
Function GetPath()Const WINDOW_HANDLE = 0Const OPTIONS = 0Set objShell = CreateObject('Shell.Application')Set objFolder = objShell.BrowseForFolder(WINDOW_HANDLE, 'Select a folder:', OPTIONS)If objFolder Is Nothing ThenWscript.QuitEnd IfSet objFolderItem = objFolder.SelfGetPath = objFolderItem.PathEnd FunctionFunction SaveToExcel(src_file,dest_file)csv_format = 1 ’6另存为csv,1另存为xlsSet objFSO = CreateObject('Scripting.FileSystemObject')Dim oExcelSet oExcel = CreateObject('Excel.Application')oExcel.DisplayAlerts=falseDim oBookSet oBook = oExcel.Workbooks.Open(src_file)oBook.Worksheets(1).ActivateoBook.SaveAs dest_file, csv_formatoBook.Close FalseoExcel.QuitEnd FunctionDim i : i=0Set oFso = CreateObject('Scripting.FileSystemObject') Set oFolder = oFso.GetFolder(GetPath()) Set oFiles = oFolder.Files For Each oFile In oFilesIf Right(oFile.Path,3)='xls' or Right(oFile.Path,4)='xlsx' Then SaveToExcel oFile.Path,oFile.Pathi=i+1End IfNextMsgBox '总共处理了'&i&'个EXCEL文件'Wscript.Quit
问题解答
回答1:用vbs打开再另存为EXCEL,再读取
回答2:你这个本来就是excel格式干嘛使用文本打开,你下载后直接panda读就可以了
相关文章:
1. angular.js - ng-grid 和tabset一起用时,grid width默认特别小2. 能用Nginx服务小型购物网站的web吗?3. android - 美团筛选处筛选条件停靠+条件点击滑动到顶部。4. python for循环中的函数只能运行一次?5. python - pyspider爬取了接近1G的数据,无法导出csv?6. javascript - Vue.js2.0不能使用debounce后大伙一般是如何解决延迟请求的问题的呢。7. html - 爬虫时出现“DNS lookup failed”,打开网页却没问题,这是什么情况?8. python的文件读写问题?9. html5 - 在一个页面中 初始了两个swiper 不知道哪里错了 一直不对10. 请问是对象还是数组
