我的编程空间,编程开发者的网络收藏夹
学习永远不晚

解决Python报错ValueError: No engine for filetype: ‘xls‘

短信预约 -IT技能 免费直播动态提醒
省份

北京

  • 北京
  • 上海
  • 天津
  • 重庆
  • 河北
  • 山东
  • 辽宁
  • 黑龙江
  • 吉林
  • 甘肃
  • 青海
  • 河南
  • 江苏
  • 湖北
  • 湖南
  • 江西
  • 浙江
  • 广东
  • 云南
  • 福建
  • 海南
  • 山西
  • 四川
  • 陕西
  • 贵州
  • 安徽
  • 广西
  • 内蒙
  • 西藏
  • 新疆
  • 宁夏
  • 兵团
手机号立即预约

请填写图片验证码后获取短信验证码

看不清楚,换张图片

免费获取短信验证码

解决Python报错ValueError: No engine for filetype: ‘xls‘

Python环境介绍

Python3.11,编译器Pycharm 2022.3

报错原因分析

对应Python3.11版本的Pandas无法兼容低版本的xls。

 

 

解决方案

  • 以csv格式输出。
  • 以xlsx格式输出。更改后可能会出现报错,没有安装openxls库,这时,只需安装该库即可正常运行。

 

更正后代码

# 水情日报 数据下载# Water information data download# Water information url# http://61.163.88.227:8006/hwsq.aspx?sr=0nkRxv6s9CTRMlwRgmfFF6jTpJPtAv87# Design by HanLin# Parameters start =======# Start date (include)开始日期Start_date = '2003-05-20'# End date (include)结束日期End_date = '2003-06-24'# Result save path保存路径# (Under the Download_data folder)Save_path = r'F:\water'  #自己更改一下# Parameters end =======import warningswarnings.filterwarnings('ignore')import osimport sysimport numpy as npimport pandas as pdimport bs4from bs4 import BeautifulSoupimport requestsimport datetimeWater_info_url=r'http://61.163.88.227:8006/hwsq.aspx?sr=0nkRxv6s9CTRMlwRgmfFF6jTpJPtAv87'# Initial login header# In order to achieve cookieheader_first={    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,**',    'Accept-Encoding': 'gzip, deflate',    'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,zh-TW;q=0.6',    'Cache-Control': 'no-cache',    'Connection': 'keep-alive',    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',    'Host': '61.163.88.227:8006',    'Origin': r'http://61.163.88.227:8006',    'Referer': 'http://61.163.88.227:8006/hwsq.aspx?sr=0nkRxv6s9CTRMlwRgmfFF6jTpJPtAv87',    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.53 Safari/537.36 Edg/103.0.1264.37',}# Data to be transferred要传输的数据# Use Form Datapostdata={    'ctl00$ScriptManager1': 'ctl00$ScriptManager1|ctl00$ContentLeft$Button1',    '__EVENTTARGET': '',    '__EVENTARGUMENT': '',    'ctl00$ContentLeft$menuDate1$TextBox11': '2022-06-13',    '__VIEWSTATE':'/wEPDwULLTEwMDI5NzA1NzkPZBYCZg9kFgICAw9kFgICBQ9kFgJmD2QWAgIBD2QWAgIBDxYCHglpbm5lcmh0bWwF60w8dGFibGUgd2lkdGg9Ijk4JSIgYm9yZGVyPSIwIiBjZWxscGFkZGluZz0iMCIgY2VsbHNwYWNpbmc9IjEiIGJnY29sb3I9IiNEMUREQUEiIGFsaWduPSJjZW50ZXIiPjx0cj48dGQgaGVpZ2h0PSI0MCIgYmFja2dyb3VuZD0ic2tpbi9pbWFnZXMvbmV3bGluZWJnMy5naWYiPjx0YWJsZSB3aWR0aD0iOTglIiBib3JkZXI9IjAiIGNlbGxzcGFjaW5nPSIwIiBjZWxscGFkZGluZz0iMCI+PHRyPjx0ZCBhbGlnbj0iY2VudGVyIj48ZGl2IGNsYXNzPSdmaXJzdFRpdGxlJz7msLTmg4Xml6XmiqU8L2Rpdj48ZGl2IGNsYXNzPSdzZWNUaXRsZSc+MjAyMi0wNi0yNjwvZGl2PjwvdGQ+PC90cj48L3RhYmxlPjwvdGQ+PC90cj48L3RhYmxlPjx0YWJsZSB3aWR0aD0iOTglIiBib3JkZXI9IjAiIGNlbGxwYWRkaW5nPSIyIiBjZWxsc3BhY2luZz0iMSIgYmdjb2xvcj0iI0QxRERBQSIgYWxp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yAgICAgICAgICAgICAgICAgICAgICAgICAgPC90ZD48dGQ+5rO65Y+jICAgICAgICAgICAgICAgICAgICAgICAgICA8L3RkPjx0ZD4yNi45NjwvdGQ+PHRkPjMwMjA8L3RkPjx0ZD4qNC4wMzwvdGQ+PC90cj48dHIgYWxpZ249ImNlbnRlciIgYmdjb2xvcj0iI0ZGRkZGRiI+PHRkPum7hOaysyAgICAgICAgICAgICAgICAgICAgICAgICAgPC90ZD48dGQ+5Yip5rSlICAgICAgICAgICAgICAgICAgICAgICAgICA8L3RkPjx0ZD4xMC40PC90ZD48dGQ+MjcxMDwvdGQ+PHRkPio2Ljc4PC90ZD48L3RyPjwvdGFibGU+PC90ZD48L3RyPjwvdGFibGU+ZGQX7a8AK6EFHourJJ2xgJ7zGGznTXSzg7yZvMnSVM0/Mw==',    '__VIEWSTATEGENERATOR': 'E4DC7756',    '__EVENTVALIDATION': '/wEdAAPgMurU7dGbCJhtK8P1Nstr9DkLBAR+UXBBGQ1m5cY+HY5Ggl8DGIT46Qo2GBY6Yh4fpd+LHAI2ihOULO1i+2DgH5H5WRTn9WanmVpiptZGnA==',    '__ASYNCPOST': 'true',    'ctl00$ContentLeft$Button1': '查询',}# Parameters that don't seem to be usefulparam={    'sr': '0nkRxv6s9CTRMlwRgmfFF6jTpJPtAv87'}def Generate_date_list(start_date,end_date):    date_lists=[]    start_date=datetime.datetime.strptime(start_date,'%Y-%m-%d')    end_date=datetime.datetime.strptime(end_date,'%Y-%m-%d')    # Make sure the start time is less than the end time#确保开始时间小于结束时间    if start_date > end_date:        print('Start time is greater than end time !')        sys.exit(0)    else:        while(start_date <= end_date):            date_lists.append(datetime.datetime.strftime(start_date,'%Y-%m-%d'))            start_date=start_date+datetime.timedelta(days=1)    return date_lists# Generate postdata corresponding to the datedef Generate_date_related_postdata(postdata,date):    postdata['ctl00$ContentLeft$menuDate1$TextBox11']=datedef Information_extraction(response):    response_lists=[]    # Parsing html    response = BeautifulSoup(response,'html.parser')    # Data cleaning    for single_response in response.find_all('tr'):        if len(single_response) == 5:            if isinstance(single_response.contents[0],bs4.element.Tag):                response_contents_lists=[]                for single_response_content in single_response.contents:                    single_response_content_cache=single_response_content.contents                    if len(single_response_content_cache)!=0:                        response_contents_lists.append(single_response_content_cache[0])                response_lists.append(response_contents_lists)    return response_listsdef Generate_excel(information_lists):    column_header=information_lists[0]    Result_excel=pd.DataFrame(information_lists[1:],dtype=str,columns=column_header)    return Result_exceldef Result_save(save_path,result_excel,date):    dir_name = 'Download_data'    file_path = os.path.join(save_path,dir_name)    # Check if the folder is in    if not os.path.exists(file_path):        os.makedirs(file_path)    file_name = f'{date}.xlsx' ## "xls" was replaced by "xlsx".    file_path = os.path.join(file_path,file_name)    result_excel.to_excel(file_path,header=True,index=True)if __name__=='__main__':    date_lists = Generate_date_list(Start_date,End_date)    session = requests.session()    First_response = session.post(Water_info_url,headers=header_first)    for date_list in date_lists:        Generate_date_related_postdata(postdata,date_list)        Next_response = session.post(Water_info_url, headers=header_next, data=postdata)        Next_response.raise_for_status()        Next_response.encoding = Next_response.apparent_encoding        # Get the returned infomation        Next_response = Next_response.text        Information_lists = Information_extraction(Next_response)        Result_excel = Generate_excel(Information_lists)        Result_save(Save_path,Result_excel,date_list)        print(f'Date : {date_list} ,data download is complete !')

来源地址:https://blog.csdn.net/weixin_46629224/article/details/130140478

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

解决Python报错ValueError: No engine for filetype: ‘xls‘

下载Word文档到电脑,方便收藏和打印~

下载Word文档

猜你喜欢

python chinesecalendar报错no available data for year {}怎么解决

这篇文章主要讲解了“python chinesecalendar报错no available data for year {}怎么解决”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“pytho
2023-07-05

python报错no module named怎么解决

Python报错"No module named"通常表示没有找到指定的模块。下面是一些解决这个问题的常见方法:1. 检查模块是否存在:确保你正在引用的模块确实存在于Python的安装环境中。你可以在Python的官方文档或第三方库的文档中
2023-08-15

python报错no module named如何解决

当你在Python中遇到"No module named"的错误时,意味着你尝试导入一个不存在的模块或包。解决这个问题的方法有以下几种:1. 检查模块名是否正确:请确保你输入的模块名是正确的。检查是否存在拼写错误或大小写错误。2. 检查模块
2023-09-08

Django报错ValueError: invalid literal for int() with base 10的原因及解决方法

这篇文章主要讲解了“Django报错ValueError: invalid literal for int() with base 10的原因及解决方法”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究
2023-06-02

编程热搜

  • Python 学习之路 - Python
    一、安装Python34Windows在Python官网(https://www.python.org/downloads/)下载安装包并安装。Python的默认安装路径是:C:\Python34配置环境变量:【右键计算机】--》【属性】-
    Python 学习之路 - Python
  • chatgpt的中文全称是什么
    chatgpt的中文全称是生成型预训练变换模型。ChatGPT是什么ChatGPT是美国人工智能研究实验室OpenAI开发的一种全新聊天机器人模型,它能够通过学习和理解人类的语言来进行对话,还能根据聊天的上下文进行互动,并协助人类完成一系列
    chatgpt的中文全称是什么
  • C/C++中extern函数使用详解
  • C/C++可变参数的使用
    可变参数的使用方法远远不止以下几种,不过在C,C++中使用可变参数时要小心,在使用printf()等函数时传入的参数个数一定不能比前面的格式化字符串中的’%’符号个数少,否则会产生访问越界,运气不好的话还会导致程序崩溃
    C/C++可变参数的使用
  • css样式文件该放在哪里
  • php中数组下标必须是连续的吗
  • Python 3 教程
    Python 3 教程 Python 的 3.0 版本,常被称为 Python 3000,或简称 Py3k。相对于 Python 的早期版本,这是一个较大的升级。为了不带入过多的累赘,Python 3.0 在设计的时候没有考虑向下兼容。 Python
    Python 3 教程
  • Python pip包管理
    一、前言    在Python中, 安装第三方模块是通过 setuptools 这个工具完成的。 Python有两个封装了 setuptools的包管理工具: easy_install  和  pip , 目前官方推荐使用 pip。    
    Python pip包管理
  • ubuntu如何重新编译内核
  • 改善Java代码之慎用java动态编译

目录