如何使用 wget 下载图片

如何使用 wget 下载图片

我想从http://myhomepage.com/plots/20150111-03/4711/4712.png每 3 小时。“20150111-03”是可变的,其余的是稳定的。这意味着每 3 小时下载量如下:

http://myhomepage.com/plots/20150111-01/4711/4712.png --- http://myhomepage.com/plots/20150111-02/4711/4712.png --- http://myhomepage.com/plots/20150111-03/4711/4712.png

我如何在 Windows 中使用 wget(curl)和 .bat 文件来管理它?

再见斯蒂芬

答案1

这应该可以让你开始

@echo off

:: Get current day month and year, padded with zeroes
for /f "skip=1 tokens=1-3 usebackq" %%a in (`wmic path Win32_LocalTime Get Day^,Month^,Year`) do (
    if not "%%c"=="" (
        set y=%%c
        set m=0%%b
        set d=0%%a
    )
)

set m=%m:~-2%
set d=%d:~-2%

:: Loop over image files, in this case, 100 of them
setlocal enabledelayedexpansion

for /L %%i in (1,1,100) do (
    set index=0%%i
    set index=!index:~-2!
    set url=http://myhomepage.com/plots/!y!!m!!d!-!index!/4711/4712.png
    wget -O "!y!!m!!d!-!index!.png" "!url!"
) 

endlocal enabledelayedexpansion

相关内容