VBScript - 将网页的源代码分配给变量
VBScript - Assign source code of web page to variable
我正在尝试编写一个 VBScript,它看起来可以根据网站的内容导航该网站。为此,我需要能够将每个网页的源代码分配给一个字符串变量,并让脚本在该字符串中查找某些单词。
我看到了这个建议的解决方案:
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
但这不起作用。我在别处看到这可以通过 AutoIT 实现,但我不能根据安全策略使用 AutoIT。
有什么想法吗?
将Microsoft.XMLHTTP
更改为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")
我正在尝试编写一个 VBScript,它看起来可以根据网站的内容导航该网站。为此,我需要能够将每个网页的源代码分配给一个字符串变量,并让脚本在该字符串中查找某些单词。
我看到了这个建议的解决方案:
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
但这不起作用。我在别处看到这可以通过 AutoIT 实现,但我不能根据安全策略使用 AutoIT。
有什么想法吗?
将Microsoft.XMLHTTP
更改为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")