VBS / Javascript URL复杂应用程序

时间:2014-01-24 00:22:05

标签: javascript html search vbscript

好吧所以我对VBS很新,而不是Javascript,但我认为这是一个复杂的问题。

我尝试做的最好是创建一个VBScript,可用于加载URL并在页面文本或源中搜索短语。

例如“http://www.youtube.com/watch?v=21Ox58OKFmo”。我想知道我怎么能用另一个数字来代替“v = '21Ox58OKFmo'”。基本上说v = 55555,我希望程序为该55555添加1并使其成为55556并重新加载页面并搜索一个单词或一段文本。当它确实发现该文本时,它会返回给我,告诉我它找到了这个短语。

  

这样的东西?

     
    

var numberChange = 55555

         

load.URL(http://www.youtube.com/v= “numberChange”)'

         

///我明白,不管怎么说都没有,但是你明白了。

         

///然后有一些东西在该页面上搜索一个短语。

         

search.text( “你好”);     如果text = 0则numberChange + 1

         

///程序循环再次每次向变量添加1,直到它在页面上找到短语>>“Hello”。

  

我还需要确保它实际停在一个合理的数字,以便我的计算机不会继续运行该程序。

任何帮助将不胜感激

2 个答案:

答案 0 :(得分:0)

  1. 使用CreateObject(“MSXML2.ServerXMLHTTP”)获取网页。本网站提供的样本。
  2. 使用“Pos”功能在下载网页中查找文字

答案 1 :(得分:0)

这样的事情应该有效:

url    = "http://www.example.com/"
phrase = "..."

'load the page specified by the variable "url"
Set req = CreateObject("Msxml2.XMLHTTP.6.0")
req.open "GET", url, False
req.send

If req.status = 200 Then
  'if the page was successfully loaded, write the HTML to an HTMLFile object,
  'which will allow to retrieve the plain text (without HTML tags) from it
  Set html = CreateObject("HTMLFile")
  html.Write req.responseText

  If InStr(html.body.innerText, phrase) > 0 Then
    'if the plain text contains the phrase do this
    WScript.Echo "Phrase found."
  Else
    'if the plain text doesn't contain the phrase do something else
    WScript.Echo "Phrase not found."
  End If
Else
  'if the page couldn't be loaded, show a message with status information
  WScript.Echo "Cannot load " & url & ": [" & req.status & "] " & req.statusText
End If