如何在PowerShell中使用Invoke-Webrequest下载图像?
要使用Invoke-WebRequest命令从网页下载图像,我们可以使用结果中的images属性来检索图像URL,然后我们可以使用该方法在特定位置下载它们。考虑我们有URI:https://theautomationcode.com来检索图像。
运行以下命令后,您可以在此处看到Images属性。
Invoke-WebRequest -Uri "https://theautomationcode.com/feed/"
要检索图像网址,
$req = Invoke-WebRequest -Uri "https://theautomationcode.com/feed/" $req.Images | Select -ExpandProperty src输出结果
https://i1.wp.com/theautomationcode.com/wp-content/uploads/2020/11/image-9.png?resize=178%2C60&ssl=1 https://i0.wp.com/theautomationcode.com/wp-content/uploads/2020/11/image-10.png?resize=640%2C68&ssl=1
以上所有URL均指向图像,因此我们可以下载它们。
$wc = New-Object System.Net.WebClient
$req = Invoke-WebRequest -Uri "https://theautomationcode.com/feed/"
$images = $req.Images | Select -ExpandProperty src
$count = 0
foreach($img in $images){
$wc.DownloadFile($img,"C:\Temp\WebImages\img$count.jpg")
}输出图像将存储在C:\temp\WebImages文件夹中。
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短