从URL批量下载图像,用于 [英] batch download images from url with for

查看:95
本文介绍了从URL批量下载图像,用于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用以下格式从site.com/folder/下载300张图像:1.png2.png ... 300.png

I need to download 300 images from site.com/folder/ using the following format: 1.png, 2.png ... 300.png

是否可以在批处理文件中或使用命令提示符来执行此操作?

Is there a way to do this inside a batch file or using the command prompt?

推荐答案

数字文件下载器1.0

这是一个完整的批处理脚本,可以完全满足您的要求.您无需下载任何可执行文件,这是100%批处理脚本,它可以在任何(最新)Windows安装中使用.

Numbered-Files Downloader 1.0

Here is a complete batch script that is doing exactly what you asked for. You don't need to download any executable files, this is 100% batch script and it should works on any (recent) Windows installation.

所有您需要做的就是编辑 _URL 变量(第11行),并将"example.com/folder ..."替换为您要下载的文件的实际URL.之后,您可以运行脚本并获取文件.

All you need to do is to edit the _URL variable (Line 11) and replace "example.com/folder..." with the actual URL of the files you want to download. After that, you can run the script and get your files.

  • 请注意,在您的URL中,以下字符串: _NUMBERS _ 是一个关键字过滤器,将由最终下载功能中的递增数字代替.
  • Note that in your URL, this string: _NUMBERS_ is a keyword-filter that will be replaced by the incremented numbers in the final download function.

所有下载的文件将保存在此脚本所在的目录中.您可以通过取消注释 _SAVE_PATH 变量(第15行)来选择其他目录.

All your downloaded files will be saved in the directory where this script is located. You can choose an other directory by uncommenting the _SAVE_PATH variable (Line 15).

最后,可以更改以下变量来配置数字序列:

Finally the following variables can be changed to configure the series of numbers:

_START :文件编号以此值开头.
_STEP   :在每个文件之间切换.
_END    :文件编号以该值结尾.

_START : The file numbers starts with this value.
_STEP   : Step between each files.
_END    : The file numbers ends with this value.

随时修改&如果您需要...,请增强此脚本.

Feel free to modify & enhance this script if you need to...

@echo off
setlocal ENABLEDELAYEDEXPANSION

rem QUESTION FROM:
rem https://stackoverflow.com/questions/45796990/batch-download-images-from-url-with-for#45796990


:VARIABLES

rem FILES URL
SET _URL=https://example.com/folder/_NUMBERS_.png

rem SAVE PATH
SET _SAVE_PATH=%~dp0
rem SET _SAVE_PATH=C:\Folder\

SET _START=1
SET _STEP=1
SET _END=300


rem HOW TO USE THE DOWNLOAD FUNCTION (SINGLE FILE):
rem
rem SET _URL=https://www.google.ca/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png
rem SET _SAVE_PATH=%~dp0_Google.png
rem CALL :DOWNLOAD %_URL% %_SAVE_PATH%


:DETAILS_DISPLAY

ECHO.
ECHO SCRIPT:     Numbered-Files Downloader 1.0
ECHO AUTHOR:     Frank Einstein
ECHO.
ECHO.
ECHO INPUTS
ECHO _URL:       %_URL%
ECHO _SAVE_PATH: %_SAVE_PATH%
ECHO.
ECHO _START:     %_START%
ECHO _STEP=      %_STEP%
ECHO _END=       %_END%
ECHO.
ECHO.


:PATH_FIX

rem REMOVE THE LAST CHAR IF IT IS "\"
IF "%_SAVE_PATH:~-1%" == "\" SET "_SAVE_PATH=%_SAVE_PATH:~0,-1%"


:DOWNLOAD_LOOP

SET FINAL_URL=%_URL%

FOR /L %%G IN (%_START%,%_STEP%,%_END%) DO (

    rem REPLACE URL'S KEYWORD WITH NUMBERS
    SET NUM=%%G
    SET FINAL_URL=%FINAL_URL:_NUMBERS_=!NUM!%

    rem CUMSTOM BATCH FUNCTION FOR DOWNLOADING FILES
    rem 
    rem SYNTAX:
    rem CALL :DOWNLOAD %URL% %SAVE_PATH%

    CALL :DOWNLOAD !FINAL_URL!

)

GOTO :EXIT


rem FUNCTIONS

:DOWNLOAD

setlocal

SET "_URL_=%1"
SET "_SAVE_TO_=%2"

rem EXTRACT THE FILENAME FROM URL (NEED TO FIX THIS PART?)

FOR %%F IN ("%_URL_%") DO SET _FILE_NAME_=%%~nxF
IF "%_SAVE_TO_:~-1%" == "\" SET "_SAVE_TO_=%_SAVE_TO_:~0,-1%"
IF [%2]==[] SET _SAVE_TO_=%~dp0%_FILE_NAME_%
IF NOT [%2]==[] SET "_SAVE_TO_=%_SAVE_TO_%\%_FILE_NAME_%"


:BITSADMIN

ECHO.
ECHO DOWNLOADING: "%_URL_%"
ECHO SAVING TO:   "%_SAVE_TO_%"
ECHO.

bitsadmin /transfer mydownloadjob /download /priority normal "%_URL_%" "%_SAVE_TO_%"

rem BITSADMIN DOWNLOAD EXAMPLE
rem bitsadmin  /transfer mydownloadjob  /download  /priority normal http://example.com/filename.zip  C:\Users\username\Downloads\filename.zip

endlocal

GOTO :EOF


:EXIT

ECHO.
ECHO.
ECHO END OF EXECUTION
ECHO.

PAUSE & EXIT /B

这篇关于从URL批量下载图像,用于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆