【发布时间】:2020-06-30 18:01:54
【问题描述】:
我想从名为 hdrihaven.com 的网站下载多个 .hdr 文件。 我对 python 的了解不是很好,但这是我迄今为止尝试过的:
import requests
url = 'https://hdrihaven.com/files/hdris/'
resolution = '4k'
file = 'pump_station' #would need to be every file
url_2k = url + file + '_' + resolution + '.hdr'
print(url_2k)
r = requests.get(url_2k, allow_redirects=True)
open(file + resolution + '.hdr', 'wb').write(r.content)
理想情况下,file 会遍历目录中的每个文件。
提前感谢您的回答!
编辑
我在 github 上找到了一个可以满足我需求的脚本:https://github.com/Alzy/hdrihaven_dl。我在这里对其进行了编辑以满足我的需求:https://github.com/ktkk/hdrihaven-downloader。它使用 cmets 中建议的循环遍历所有可用文件列表的技术。
我发现请求模块以及 urllib 与从例如本地下载相比非常慢。铬合金。如果有人知道如何加快这些速度,请告诉我。
【问题讨论】:
-
通过解析返回的内容,从相应的url获取文件列表,然后遍历该列表并单独检索每个文件。
-
那么当你感觉很疯狂的时候,添加多处理来并行处理