使用wget批量下载,下载后立即使用python脚本修改文件

Download in batch with wget and modify files with a python script immediately after download

我想从 CHELSA 数据库下载气候数据。

以编程方式执行此操作的一种方法是使用 wget,遵循他们的指南:

Download the file (envidatS3paths.txt), install wget and then run the command: wget --no-host-directories --force-directories --input-file=envidatS3paths.txt .

但是,对于每个下载的文件,我想对它们执行一个操作(基本上,trim挖掘数据,因为它们很大)。

我查看了 wget 手册,但我找不到任何与下载之间 运行 的中间脚本相关的内容。

我可能 运行 第二个后台命令来查找任何新下载的文件并 trim 它,但我想知道第一个解决方案是否可以更直接。

您可以 运行 对输入文件和每个文件进行 for 循环 运行 wget -O $new_file_name $url

尝试这样的事情 -

bash

for url in $(cat envidatS3paths.txt); do wget -O $(echo $url | sed "s/\//_/g").out $url  ; done

python

for url in opened_file:
    subprocess.Popen(f'wget -O {url.rsplit('\')[1]} {url}')