python - 直接在 Python 中从网站 rar 文件夹中读取 csv 文件
问题描述
我想直接从网站 rar 文件夹中读取 csv 文件。
我有一个 rar 文件夹的链接:
http://.../folder.rar
其中有几个 csv 文件。
如何在 Python 中直接提取每个文件?
我找到了remoteunrar包,并尝试了以下方法(如文档中所述):
import remoteunrar
with remoteunrar('http://.../folder.rar') as rar:
rar.extract('file.csv')
但它返回一个错误:
TypeError: 'module' object is not callable
(您可以尝试以ecobee_thermostat为例;如果给出相同的错误)
如何在 Python 中直接读取这些文件?
解决方案
您可以使用模块和
我的作品zipfile
一起使用requests
import requests, zipfile, io
r = requests.get('http://archive.ics.uci.edu/ml/machine-learning-databases/00442/Ecobee_Thermostat/mirai_attacks.rar?')
z = zipfile.ZipFile(io.BytesIO(r.content))
z.extractall("/path/location")
推荐阅读
- javascript - 在 ExpansionPanelSummary [React Material-UI] 中定位内容
- visual-studio-code - 语言服务器如何访问与源文件位于同一目录中的文件
- javascript - XmlHttpRequest 不工作,说模块未定义
- c# - 如何使用随机数据 c# 自动填充类?
- swift - ARKit:不在视图中时停止 AVPlayer 音频
- micronaut - Micronaut 中的基类注入何时发生
- python - 给定根节点,是否有一种遍历路径的新模型方法?
- javascript - 如何在 Angular 循环中运行下一个服务调用之前等待对我的控制器的每个服务调用?
- excel-formula - Sumif 行并向下拖动以增加列(索引 - 匹配)
- python - 我可以在条件后使用熊猫提取行吗?