0

I'm trying to write a VBScript that looks navigates a website based on the content of that website. To do that, I need to be able to assign the source code of each web page to a string variable and have the script look through that string for certain words.

I have seen this proposed as a solution:

Function GetSourceCode(url)
     Set objHttp = CreateObject("Microsoft.XMLHTTP")
     bGetAsAsync = False

     objHttp.open "GET", url, bGetAsAsync
     objHttp.send

     If objHttp.status <> 200 Then
         wscript.Echo "unexpected status = " & objHttp.status & vbCrLf & objHttp.statusText
         wscript.Quit
     End If

     'MsgBox objHttp.responseText

     GetSourceCode = objHttp.responseText
End Function

but that does not work. I've seen elsewhere that this is possible with AutoIT, but I cannot use AutoIT per security policy.

Any ideas?

1

1 Answer 1

1

Change Microsoft.XMLHTTP to Msxml2.ServerXMLHTTP

Function GetSourceCode(url)
     Set objHttp = CreateObject("Msxml2.ServerXMLHTTP")
     bGetAsAsync = False

     objHttp.open "GET", url, bGetAsAsync
     objHttp.send

     If objHttp.status <> 200 Then
         wscript.Echo "unexpected status = " & objHttp.status & vbCrLf & objHttp.statusText
         wscript.Quit
     End If

     'MsgBox objHttp.responseText

     GetSourceCode = objHttp.responseText
End Function

WScript.Echo GetSourceCode("https://anothervps.com/api/phpver")

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.