curl - 将 cURL 与两个匹配范围结合使用

标签 curl web-scraping wget

我正在尝试使用 cURL 下载一批图像。 图像全部保存在单独的目录中,名称与图像文件名相同。

我厌倦了使用方括号来设置两个范围,一个用于文件名,一个用于目录,但这不起作用,因为命令先遍历第一个范围,然后遍历第二个范围,而不是两个范围都向上同时加 1。

curl -f "https://example.com/images/products/[100-200]/[100-200].jpg" -o "/Users/user/Desktop/output/#1.jpg"

是否可以设置cURL命令,使目录和文件名编号每次都加1?

示例:

https://example.com/images/products/100/100.jpg
https://example.com/images/products/101/101.jpg
https://example.com/images/products/102/102.jpg
https://example.com/images/products/103/103.jpg

等等...

最佳答案

据我所知,这不能通过curl url globbing 来完成。您可以使用现有代码下载所有内容,然后删除不需要的文件,但这效率很低。

你最好的选择可能是使用循环:

for index in {100..200}; do 
  curl -f "https://example.com/images/products/$index/$index.jpg" -o "/Users/user/Desktop/output/$index.jpg"
done

关于curl - 将 cURL 与两个匹配范围结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51603006/

相关文章:

php - 为什么 curl 会忽略 CURLOPT_TIMEOUT_MS(但尊重 CURLOPT_TIMEOUT)?

python - 如何获取第一个span标签?

ssl - 在 Jmeter 中将 --no-check-certificate 添加到 wget

c - 如何在特定界面上使用 cURL

ssl - libcurl : how to use TPM private key for mutual SSL authentication

python - 使用 Selenium 将鼠标悬停在元素上

vba - 设置 iDoc = IE.Document 在 VBA 中给出运行时错误

curl - 来自专用服务器的 HTTPS 网站的 wget

linux - debian wget 无法 fork

windows - 在 Windows 7 上安装 curl 后缺少 libcurl-4.dll