使用VBA或VB6从URL(https)下载xml文件 [英] Download xml file from url (https) with VBA or VB6
本文介绍了使用VBA或VB6从URL(https)下载xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想下载此文件
Internet Explorer无法显示此页面:-(。
您能帮我吗?
解决方案
VBScript是
这是使用IE 。
错误恢复下一个
设置ie = CreateObject( InternetExplorer.Application)
msgbox ie.offline
' ie.offline = true
ie.Visible = 1
ie.Silent = 1
ie.Navigate2 http://www.smh.com.au
做
Msgbox ie.document.readystate()
wscript.sleep 500
循环直到ie.document.readystate = complete
Msgbox ie.document.body.innertext
即.refresh
即.quit
这使用MSHTTPXML。目的是显示为什么您的URL不起作用。
Set objHTTP = CreateObject( WinHttp.WinHttpRequest.5.1)
Url = http://www.smh.com.au
objHTTP.Open POST,Url,False
objHTTP.setRequestHeader User-Agent, Mozilla / 5.0(Windows NT 10.0; Win64; x64)AppleWebKit / 537.36(KHTML,例如Gecko)Chrome / 63.0.3239.132 Safari / 537.36
objHTTP.setRequestHeader Referer, http:// finra-markets .morningstar.com / bondSearch.jsp
objHTTP.setRequestHeader Content-type, application / x-www-form-urlencoded
'objHTTP.send( count = 1& curPage = 1& ; query = {'Keywords':[{'Name':'debtOrAssetClass','Value':'3'},{'Name':'showResultsAs','Value':'B'}]}& searchtype = B& sortfield = issuerName& sorttype = 1& start = 40)
objHTTP.send
Msgbox objHTTP.Status
Msgbox objHTTP.responseText
Msgbox objHTTP.getAllResponseHeaders
使用上面的ADODB将文件保存到磁盘。
设置fso = CreateObject( Scripting.FileSystemObject)
设置Outp = Wscript.Stdout
设置wshShell = CreateObject( Wscript.Shell)
设置ShApp = CreateObject( Shell .Application)
错误恢复下一个
设置文件= WScript.CreateObject( Microsoft.XMLHTTP)
File.Open GET, http://definitionupdates.microsoft.com /download/definitionupdates/safetyscanner/x86/msert.exe:200\",False
File.setRequestHeader User-Agent, Mozilla / 4.0(兼容; MSIE 8.0; Windows NT 6.0;三叉戟/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 1.1.4322; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C; .NET4.0E; BCD2000; BCD2000)
File.Send
'如果err.number<> 0则
wscript.echo
wscript.echo获取文件时出错
wscript.echo =================
wscript.echo
wscript.echo错误& err.number& (0x& hex(err.number)&)& err.description
wscript.echo源& err.source
wscript.echo
wscript .echo HTTP错误& File.Status&& File.StatusText
wscript.echo File.getAllResponseHeaders
'else
出错时转到0
设置BS = CreateObject( ADODB.Stream)
BS.type = 1
BS.open
BS.Write File.ResponseBody
BS.SaveToFile ShApp.Namespace(& h10) .self.path& \safetyscanner.exe,2
wshshell。运行 c:\users\safetyscanner.exe,1,假
'如果
I would like to download this file https://www.omniva.ee/locations.xml with VBA or VB6. I can do it with C# using webClient but i don't know how do it in VBA or VB6. Is it possible without IE API? Because it doesn't work for me:
Internet explorer can't show this page :-(. Can you help me please?
解决方案
VBScript is pastable into VBA or VB6. You don't specify what you don't like.
This uses IE.
On Error Resume Next
Set ie = CreateObject("InternetExplorer.Application")
msgbox ie.offline
' ie.offline = true
ie.Visible = 1
ie.Silent = 1
ie.Navigate2 "http://www.smh.com.au"
Do
Msgbox ie.document.readystate()
wscript.sleep 500
Loop Until ie.document.readystate = "complete"
Msgbox ie.document.body.innertext
ie.refresh
ie.quit
This uses MSHTTPXML. The purpose is to show why your URL doesn't work.
Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
Url = "http://www.smh.com.au"
objHTTP.Open "POST", Url, False
objHTTP.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
objHTTP.setRequestHeader "Referer", "http://finra-markets.morningstar.com/bondSearch.jsp"
objHTTP.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
'objHTTP.send ("count=1&curPage=1&query={'Keywords':[{'Name':'debtOrAssetClass','Value':'3'},{'Name':'showResultsAs','Value':'B'}]}&searchtype=B&sortfield=issuerName&sorttype=1&start=40")
objHTTP.send
Msgbox objHTTP.Status
Msgbox objHTTP.responseText
Msgbox objHTTP.getAllResponseHeaders
This uses above plus ADODB to save the file to disk.
Set fso = CreateObject("Scripting.FileSystemObject")
Set Outp = Wscript.Stdout
Set wshShell = CreateObject("Wscript.Shell")
Set ShApp = CreateObject("Shell.Application")
On Error Resume Next
Set File = WScript.CreateObject("Microsoft.XMLHTTP")
File.Open "GET", "http://definitionupdates.microsoft.com/download/definitionupdates/safetyscanner/x86/msert.exe:200", False
File.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 1.1.4322; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C; .NET4.0E; BCD2000; BCD2000)"
File.Send
' If err.number <> 0 then
wscript.echo ""
wscript.echo "Error getting file"
wscript.echo "=================="
wscript.echo ""
wscript.echo "Error " & err.number & "(0x" & hex(err.number) & ") " & err.description
wscript.echo "Source " & err.source
wscript.echo ""
wscript.echo "HTTP Error " & File.Status & " " & File.StatusText
wscript.echo File.getAllResponseHeaders
' else
On Error Goto 0
Set BS = CreateObject("ADODB.Stream")
BS.type = 1
BS.open
BS.Write File.ResponseBody
BS.SaveToFile ShApp.Namespace(&h10).self.path & "\safetyscanner.exe", 2
wshshell.Run "c:\users\safetyscanner.exe", 1, False
' End If
这篇关于使用VBA或VB6从URL(https)下载xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文