Powershell - 从图像 url 下载图像 [英] Powershell - Download Image from an image url

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

问题描述

对 powershell 的了解有限.
我尝试从图像 url 下载图像.例如像这样:"http://hdwallpaperia.com/wp-content/uploads/2014/01/Mc-Laren-P1-Wallpaper-Image-Picture-640x360.jpg"

limited knowledge with powershell.
I try to download a image from an image url. for example like this : "http://hdwallpaperia.com/wp-content/uploads/2014/01/Mc-Laren-P1-Wallpaper-Image-Picture-640x360.jpg"

在访问链接之前,我必须先登录.这是我的登录页面 html 代码:

Before to reach the link, I have to login first. here is My login page html code:

<tr>
    <td colspan="2">Please enter your user name and password below:</td>
</tr>
<tr style="height: 10px;"><td></td></tr>
<tr>
    <td>User Name:</td>
    <td><input name="login_username" style="width: 295px;" type="text" size="40" value=""></td>
</tr>
<tr>
    <td>Password:</td>
    <td><input name="login_password" style="width: 295px;" type="password" size="40"></td>
</tr>
<tr>
    <td>Realm:</td>
    <td>
        <select name="realm" style="width: 295px;"><option value="local">Local</option><option value="ldap" selected="">LDAP</option>
        </select>
    </td>
</tr>
    <tr style="height: 10px;"><td></td></tr>
<tr>
    <td><input type="submit" value="Login"></td>
</tr>   

这是我的powershell代码:

Here is my powershell code :

$url = "http://local_machine/example_640x360.jpg"

$ie = New-Object -com InternetExplorer.Application
$ie.visible = $true
$ie.navigate($url)

$ie.Document.getElementByid("login_username").value = "$Account"
$ie.Document.getElementByid("login_password").value = "$Password"
$ie.Document.getElementByid("realm").value = "LDAP"

$Log_In=$ie.Document.getElementsByTagName("input") | where-object {$_.type -eq "submit"}
$Log_In.click();

while($ie.Busy) {Start-Sleep -s 1}

#$ie.Document.Body | Out-File -FilePath "c:\temp\test.jpg"
$ie.quit()

我可以成功登录并到达img链接,但不知道如何下载图片.什么命令可以帮助我下载?

I can successfully login and reach the img link, but don't know how to download the image. What command can helps me to download?

推荐答案

您使用 COM 使其过于复杂.我无法测试这些自动取款机,但它们应该可以工作.

You're overcomplicating it using COM. I couldn't test these atm., but they should work.

#Solution 1 - WebClient
$url = "http://www.united.no/wp-content/uploads/2014/03/moyesliver.jpg"

$wc = New-Object System.Net.WebClient
$wc.DownloadFile($url, "C:\temp\test.jpg")


#Solution 2 - never tried this before
Invoke-WebRequest $url -OutFile C:\temp\test.jpg

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

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