如何在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文件夹中。
热门推荐
1 训练狗狗工作
4 狗狗定点排便训练
5 狗狗训练吠叫
6 狗狗尿垫训练
7 狗狗训练座
8 狗狗训练攻略
9 狗狗训练记
10 做训练狗狗
11 狗狗训练词
12 狗狗谢谢怎么训练
13 狗狗训练如厕
14 狗狗太凶怎么训练
15 狗狗训练它
16 狗狗克制训练
17 训练基地狗狗
18 怎么样训练狗狗大小硬