如何使用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
'-----------------------------------------------------------------------------------------------

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...