【问题标题】:How to save many CSV files from URL如何从 URL 保存许多 CSV 文件
【发布时间】:2014-02-11 17:55:52
【问题描述】:

我有许多需要从 URL 获取的 CSV 文件。我找到了这个参考:How to read a CSV file from a URL with Python?

它几乎可以完成我想要的事情,但我不想通过 Python 读取 CSV 然后必须保存它。我只想将 CSV 文件从 URL 直接保存到我的硬盘。

我对 for 循环和循环浏览我的 URL 没有任何问题。只需保存 CSV 文件即可。

【问题讨论】:

标签: python url csv


【解决方案1】:

如果您只想保存一个 csv,那么我根本不建议使用 python。事实上,这更像是一个unix问题。在这里假设您正在使用某种 *nix 系统,我建议您只使用wget。例如:

wget http://someurl/path/to/file.csv

你可以像这样直接从 python 运行这个命令:

import subprocess
bashCommand = lambda url, filename: "wget -O %s.csv %s" % (filename, url)
save_locations = {'http://someurl/path/to/file.csv': 'test.csv'}
for url, filename in save_locations.items():
    process = subprocess.Popen(bashCommand(url, filename).split(), stdout=subprocess.PIPE)
    output = process.communicate()[0]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-16
    • 1970-01-01
    • 2020-08-10
    相关资源
    最近更新 更多