Wget 是一个非常流行的命令行工具,用于下载文件和网站内容。它支持HTTP、HTTPS和FTP协议,以及HTTP代理。以下是如何在Windows系统中使用wget.exe的一些常见示例。
基础用法
下载单个文件
下载一个文件到当前目录:
wget.exe http://example.com/file.zip
指定下载目录
使用-P选项下载文件到指定目录:
wget.exe -P D:/downloads http://example.com/file.zip
下载并重命名文件
使用-O(大写字母O)选项下载文件并以不同的文件名保存:
wget.exe -O D:/downloads/newname.zip http://example.com/file.zip
高级用法
断点续传
如果下载过程中断,使用-c选项可以继续未完成的下载:
wget.exe -c http://example.com/file.zip
下载整个网站
使用-m(镜像)选项下载整个网站:
wget.exe -m http://example.com/wget -r -np -nH -e robots=off http://demo.mxyhn.xyz:8020/cssthemes4/cpts_648_bnl/
限制下载速度
使用--limit-rate选项限制下载速度,例如限制为100KB/s:
wget.exe --limit-rate=100k http://example.com/file.zip
下载匹配模式的文件
使用-r(递归)和-A选项下载特定类型的文件:
wget.exe -r -A.pdf http://example.com/
使用文本文件列表下载多个文件
- 首先创建一个包含URL列表的文本文件,例如urls.txt:
http://example.com/file1.ziphttp://example.com/file2.ziphttp://example.com/file3.zip
- 使用-i选项下载列表中的所有文件:
wget.exe -i urls.txt
使用批处理或PowerShell脚本
批处理脚本
创建一个download.bat文件,并输入以下内容:
@echo offsetlocal enabledelayedexpansionset LIST=( http://example.com/file1.zip http://example.com/file2.zip http://example.com/file3.zip)for %%i in %LIST% do ( wget.exe %%i)
双击运行或在命令行中输入download.bat来执行脚本。
PowerShell 脚本
创建一个download.ps1文件,并输入以下内容:
$urls = @( 'http://example.com/file1.zip', 'http://example.com/file2.zip', 'http://example.com/file3.zip')foreach ($url in $urls) { wget.exe $url}
在PowerShell中运行脚本:.\download.ps1。
结论
wget.exe是一个功能强大的工具,可以帮助你自动化下载任务。通过以上示例,你可以学会如何使用它来下载单个文件、多个文件,甚至整个网站的内容。记得在使用这些命令之前,确保你的wget.exe可执行文件已经在系统的环境变量中,或者你在命令行中提供了正确的路径。