使用VBA XMLhttp加载数据

时间:2016-07-13 01:53:28

标签: excel vba http xmlhttprequest msxml

我尝试使用XMLhttp从网站下载数据。 例如,请访问此网站:http://cmg.cdec-sic.cl/Modulos/CMg/CDEC_CMgBarras.aspx

我试图填写表格,但无论我做什么,所有返回的都是填写了默认值的网页。 必须在barra场显示之前填充张力场。

到目前为止我的代码是:

Dim xml As MSXML2.XMLHTTP60

Set xml = CreateObject("MSXML2.XMLHTTP.6.0")
Const Signinurl As String = "http://cmg.cdec-sic.cl/Modulos/CMg/CDEC_CMgBarras.aspx" 
Const para As String = "ctl00%5FMainContent%5FddlEjercicio%5FInput=" & "2014" & _
    "&ctl00%5FMainContent%5FddlMes%5FClientState=" & "julio" & _
    "&ctl00%5FMainContent%5FddlTension%5FClientState=" & "220" & _
    "&ctl00%5FMainContent%5FddlMoneda%5FClientState=" & "USD"
Set xml = sendHttpRequest(xml, Signinurl, para)

Set objIE = CreateObject("InternetExplorer.Application")
objIE.navigate "about:blank"
objIE.Visible = True

objIE.document.body.innerHTML = xml.responsetext



where the sendHttpRequest function is:


Public Function sendHttpRequest(xml As MSXML2.XMLHTTP60, base As String, fdata As String) As MSXML2.XMLHTTP60

 With xml

  .Open "POST", base, False
  .setRequestHeader "content-type", "application/x-www-form-urlencoded"
  .send fdata

End With

'result = xml.responseText

Set sendHttpRequest = xml

End Function

当IE窗口打开时,我显示的是ejercicio设置为2016的基本网页,Mes设置为julio,Moneda设置为USD,这是默认设置。

任何帮助都会很棒。

0 个答案:

没有答案