简体   繁体   English

VBScript HTTP-如何读取DOM元素值并让服务器正确答复

[英]VBScript HTTP - how to read DOM element value and have server reply correctly

I'm having lots of trouble with a VBScript that I'm putting together that, when executed, automatically logs into a webpage. 我在使用VBScript时遇到了很多麻烦,这些问题在执行时会自动登录到网页。 The problem I'm facing at the moment is that my POST doesn't mimic correctly the same as the browser does. 我目前面临的问题是我的POST与浏览器无法正确模仿。 Any help is greatly appreciated! 任何帮助是极大的赞赏!

EDIT1: I found a sloppy way to read the DOM element value, but even then there is something wrong with my POST because it differs from that of the browser. EDIT1:我发现读取DOM元素值的方法很草率,但是即使那样,我的POST还是有问题,因为它与浏览器有所不同。

EDIT2: Helen's answer steered me in the right direction, now it works perfectly. EDIT2: Helen的答案将我引向正确的方向,现在它可以正常运行了。

This is the code: 这是代码:

Dim URL
URL = "http://192.168.0.10/login.php"

Dim http : Set http = CreateObject("Msxml2.ServerXMLHTTP.6.0")
http.Open "GET", URL, FALSE
http.Send
Dim html : Set html = CreateObject("HTMLFILE")
html.write http.responseText
' Getting the DOM element's value by it's name
Dim rnd : rnd = html.getElementsByName("rnd").[0].value
'WScript.Echo rnd
sRequest = "username=admin&password=admin&rnd=" & rnd
'Msgbox sRequest, 0, "Final sRequest"
SetCookie = http.getResponseHeader("Set-Cookie")
'Bellow I trim an unnecessary part of the cookie (; path=/;) to keep only the AuthID
SetCookie = Left(SetCookie, Len(SetCookie) - 9)
'Msgbox SetCookie, 0, "Cookie Value"
Set http = nothing

http.Open "POST", URL, False
http.setRequestHeader "Host", "192.168.0.10"
http.setRequestHeader "Content-Length", Len(sRequest)
http.setRequestHeader "Cache-Control", "max-age=0"
http.setRequestHeader "Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
http.setRequestHeader "Origin", "http://192.168.0.10"
http.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.137 Safari/537.36"
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.setRequestHeader "Referer", "http://192.168.0.10/login.php"
http.setRequestHeader "Accept-Encoding", "gzip,deflate,sdch"
http.setRequestHeader "Accept-Language", "en-US;q=0.6,en;q=0.4"
http.setRequestHeader "Cookie", SetCookie
'Msgbox SetCookie, 0, "Cookie Value"
http.Send sRequest
'Msgbox sRequest, 0, "Final sRequest"
'HTTPGet = http.responseText
Set http = nothing

Thanks again Helen! 再次感谢海伦! )

Is this random DOM element on the http://192.168.0.10/login.php page? 这是http://192.168.0.10/login.php页面上的随机DOM元素吗? You could GET the page source and load it into an HTMLFILE object. 您可以GET页面源并将其加载到HTMLFILE对象中。 Then you'll be able to extract the needed element, eg using getElementById : 然后,您将能够提取所需的元素,例如使用getElementById

http.Open "GET", "httpp://192.168.0.10/login.php", False
http.Send

Dim html : Set html = CreateObject("HTMLFILE")
html.write http.responseText

Dim rnd : rnd = html.getElementsByName("rnd").[0].value ' Replace with your element query
WScript.Echo rnd

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何单击DOM元素并使用PHP将其作为变量传递? - How can I click on a DOM element and have it pass as a variable using PHP? Symfony 2:如何在表单中正确添加集合中的元素 - Symfony 2 : How to correctly add an element in collection in the form 在DOM中克隆元素 - Cloning an element in the DOM 当所有 select 框都有一个名称时,我如何从 DOM 添加/删除 select 框,以便在提交时我从活动的 select 框中获取值? - How can I add/remove select boxes from DOM when all select boxes have one name so that upon Submit I get value from active select box? HTML表单POST显示服务器的回复 - HTML form POST shows server's reply VBScript Outlook Form如何基于ComboBox的值设置“收件人”字段? - VBScript Outlook Form How do I set the To Field based off the value of a ComboBox? “回复”值在联系表格 7(Wordpress)中不起作用 - "Reply-to" value not working in Contact Form 7 (Wordpress) 如何计算有价值的输入? - How to count input that have value? 无法读取值形式 <selected> 元素与JQuery / Javascript - Cannot read value form <selected> element with JQuery/Javascript 从表单获取字段的价值-VBscript - Getting value of field from form - VBscript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM