我想创建一个VBScript
,以在网页上查找给定的单词组合。
如果脚本找到相同的文本,请键入:hits -with echo。
我找到了here的解决方案,这部分是我想要的,但是到目前为止,我还无法对其进行转换,因此脚本无法实现我想要的功能。
您能帮助我如何将其转换为工作方式吗?还是有更好的解决方案?
我是VbScripts
的初学者,我想这样做,因为已经有一个使用vbscript完成的系统,并且我想合并此功能。
感谢您的帮助!
答案 0 :(得分:0)
您可以尝试类似的操作:使用InternetExplorer.Application
对象
Option Explicit
Call Find("StackOverflow","https://stackoverflow.com")
Call Find("google","https://www.google.com")
Call Find("yahoo","https://www.yahoo.com")
'-----------------------------------------------------------------------------------------------
Function Find(StrString,URL)
Dim Title,ie,objRegex,Matches,Data
Title = "Find a String in a webpage"
Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate(URL)
ie.Visible = false 'run ie in the background
DO WHILE ie.busy
wscript.sleep 100
LOOP
Data = ie.document.documentElement.innertext
ie.quit()
Set ie = Nothing
Set objRegex = new RegExp
objRegex.Pattern = StrString
objRegex.Global = True
objRegex.IgnoreCase = True
Set Matches = objRegex.Execute(Data)
If Matches.Count > 0 Then
MsgBox "We found this word : " & qq(StrString) &" : "& Matches.Count & " times "& vbCrLf &_
"in " & qq(URL),vbInformation,Title
End If
End Function
'-----------------------------------------------------------------------------------------------
Function qq(strIn)
qq = Chr(34) & strIn & Chr(34)
End Function
'-----------------------------------------------------------------------------------------------
或与Microsoft.XMLHTTP
对象一起使用:
Option Explicit
Call Find("StackOverflow","https://stackoverflow.com")
Call Find("google","https://www.google.com")
Call Find("Hackoo","https://pastebin.com/u/hackoo")
'-----------------------------------------------------------------------------------------------
Function Find(StrString,URL)
Dim Title,HTTP_Request,objRegex,Matches,Data
Title = "Find a String in a webpage"
Set HTTP_Request = CreateObject("Microsoft.XMLHTTP")
HTTP_Request.Open "GET", URL, False
HTTP_Request.send()
Data = HTTP_Request.responseText
Set objRegex = new RegExp
objRegex.Pattern = StrString
objRegex.Global = True
objRegex.IgnoreCase = True
Set Matches = objRegex.Execute(Data)
If Matches.Count > 0 Then
MsgBox "We found this word : " & qq(StrString) &" : "& Matches.Count & " times "& vbCrLf &_
"in " & qq(URL),vbInformation,Title
End If
End Function
'-----------------------------------------------------------------------------------------------
Function qq(strIn)
qq = Chr(34) & strIn & Chr(34)
End Function
'-----------------------------------------------------------------------------------------------