我有一个关于excel VBA HTTP请求和JavaScript的问题。我想通过"POST“在内部网站点上进行搜索,但是提交按钮似乎确实运行了一个JavaScript来重新加载站点,但我不知道怎么做。
Public Function XmlHttpTutorial()
Dim xmlhttp As New MSXML2.XMLHTTP60
Set xmlhttp = CreateObject("MSXML2.serverXMLHTTP")
Dim HTMLDoc As New HTMLDocument
Dim myurl As String
myurl = "http://www.website.de"
xmlhttp.Open "POST", myurl, False
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.setRequestHeader "User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0)1"
xmlhttp.setRequestHeader "Cookie", "serverTimeOffset=-3600149; browserTimeZone=-60;"
xmlhttp.Send ("var1=variable&var2=variable&var3=variable")
Debug.Print xmlhttp.responseText
End Function这就是按钮本身
<input type="submit" name="button" tabindex="8" value="Find" onclick="closeWindow();uppercaseForm( this.form );" class="btn-small">"closeWindow“只是关闭窗口,而"uppercaseForm”只是将输入全部大写
这是标题
<form name="arrivalQueryForm" method="post" action="/opslink/arrivalQuery.do" onsubmit="setWindowId(this, 'windowId');">setWindowID仅获取window.name和替换括号。
我不知道如何让正确的网站回来,因为到目前为止似乎什么都没有起作用。
发布于 2018-01-26 12:37:00
据我所知,VBA与HTML没有任何关系。XHR被嵌入到HTML form对象中(请注意method=post属性)。onsubmit包含在HTML表单中。
我建议您不要使用HTML form元素,而是在JavaScript中手动编写XHR脚本,这样您就可以通过button元素上的.click事件来了解该机制是如何工作的。
如果您想要从Excel内部获取/XHR,而无需打开web浏览器,则可以使用该VBA。
https://stackoverflow.com/questions/48453950
复制相似问题