我最近一直在尝试下载一个跳舞的香蕉Png(只是为了学习如何(,但运气不佳。每当我尝试某个东西时,它都会给我一个错误,说写入文件失败,并给我800A0BBC作为代码。我做错了什么?提前感谢!代码:
dim xHttp: Set xHttp = createobject("Microsoft.XMLHTTP")
dim bStrm: Set bStrm = createobject("Adodb.Stream")
xHttp.Open "GET", "https://wallpapercave.com/wp/wp5042624.png", False
xHttp.Send
with bStrm
.type = 1 '//binary
.open
.write xHttp.responseBody
.savetofile "c:tempwp5042624.png", 2 '//overwrite
end with
我不知道你的代码中是否有在额外引用之前尝试过的内容,或者你的代码格式不好;无论如何,请尝试使用此代码,将您的图像保存在桌面上创建的名为Images_PNG的文件夹中,以进行测试!
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set Ws = CreateObject("WScript.Shell")
strDirectory = "Images_PNG"
strDirectory = objFSO.BuildPath(Ws.SpecialFolders("Desktop"), strDirectory)
If not objFSO.FolderExists(strDirectory) Then objFSO.CreateFolder(strDirectory)
URL = "https://wallpapercave.com/wp/wp5042624.png"
Save2File = strDirectory & "wp5042624.png"
Call Download(URL,Save2File)
MsgBox "Terminted !",vbInformation,"Download PNG File"
'--------------------------------------------------------------------------------------------
Sub Download(URL,Save2File)
Dim File,Line,BS,ws
On Error Resume Next
Set File = CreateObject("Microsoft.XMLHTTP")
File.Open "GET",URL, False
File.Send()
If err.number <> 0 then
Line = Line & vbcrlf & "Error Getting File"
Line = Line & vbcrlf & "Error " & err.number & "(0x" & hex(err.number) & ") " & vbcrlf &_
err.description
Line = Line & vbcrlf & "Source " & err.source
MsgBox Line,vbCritical,"Error getting file"
Err.clear
wscript.quit
End If
If File.Status = 200 Then ' File exists and it is ready to be downloaded
Set BS = CreateObject("ADODB.Stream")
Set ws = CreateObject("wscript.Shell")
BS.type = 1
BS.open
BS.Write File.ResponseBody
BS.SaveToFile Save2File, 2
ElseIf File.Status = 404 Then
MsgBox "File Not found : " & File.Status,vbCritical,"Error File Not Found"
Else
MsgBox "Unknown Error : " & File.Status,vbCritical,"Error getting file"
End If
End Sub
'-------------------------------------------------------------------------