VBS通过WinHttp对象下载网页图片。

我刚才写了一个vbs脚本,该脚本通过调用com组件winhttp来获取网页中图片的数据,并且以二进制数据的形式返回。
再通过adodb.steam对象将二进制数据保存为图片文件。

Sub DownloadPic(url,strPath)
    Set Winhttp = CreateObject("WinHttp.WinHttpRequest.5.1") 
    Winhttp.Open "GET", url
    Winhttp.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded" 
    Winhttp.Send

    Set sGet = CreateObject("ADODB.Stream")
    sGet.Mode = 3
    sGet.Type = 1
    sGet.Open()
    sGet.Write(Winhttp.ResponseBody)
    sGet.SaveToFile strPath
End Sub

在此将代码分享给大家。

猜你喜欢

转载自blog.51cto.com/181647568/2477546