当前位置:   article > 正文

python直接读取网页excel文件(无需下载)_python如何获取url中的excel文件

python如何获取url中的excel文件

python直接读取网页excel文件(无需下载)

import requests
import pandas as pd

# excel链接
excel_url= 'xxx.com/xxx.xlsx'

# 注意:这里调用网页上的excel文件,需要采用post请求
ret = requests.post(excel_url)

# 保存到excel文件中,不想保存到文件,这步请忽略
# f = open("{}".format(text),"wb")
# f.write(ret.content)
# f.close()

# 这里采用pandas读取excel数据集,转为dataframe 然后就可以对数据进行操作啦
df = pd.read_excel(ret.content,header=0) #header=0 表示指定数据集第一行作为列名,根据你的需要来定
df.head()

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/249919
推荐阅读
相关标签
  

闽ICP备14008679号