如何解决如何使用VBScript在网站上搜索文本?
我想创建一个VBScript
,以在网页上查找给定的单词组合。
如果脚本找到相同的文本,请键入:hits -with echo。
我找到了here的解决方案,这部分是我想要的,但是到目前为止,我还无法对其进行转换,因此脚本无法实现我想要的功能。
您能帮助我如何将其转换为工作方式吗?还是有更好的解决方案?
我是VbScripts
的初学者,我想这样做,因为已经有一个使用vbscript完成的系统,并且我想合并此功能。
感谢您的帮助!
解决方法
您可以尝试类似的操作:使用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://www.google.com")
Call Find("Hackoo","https://pastebin.com/u/hackoo")
'-----------------------------------------------------------------------------------------------
Function Find(StrString,HTTP_Request,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),Title
End If
End Function
'-----------------------------------------------------------------------------------------------
Function qq(strIn)
qq = Chr(34) & strIn & Chr(34)
End Function
'-----------------------------------------------------------------------------------------------
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。