VBS URL程序帮助! [英] VBS URL Program Help!

查看:67
本文介绍了VBS URL程序帮助!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于任何VBS / Javascript编码器都可以快速提问。基本上我正在创建一个脚本,用于扫描网站上的纯文本短语,然后告诉我它是否存在;但是,如果它没有找到任何内容,我需要它来更改部分URL,然后
重新加载页面并再次搜索。基本上就像
b
$
" http://www.youtube.com/watch=?55555"

它会搜索说出这个词"兔子" ;.如果它没有在那里找到那个词,那么它将一个添加到"55555"。使其成为"55556"然后搜索该页面等等。
$


这是我到目前为止所用的。

Alright Quick question for any VBS/Javascript coders out there. Basically I am making a script that scans a website for a phrase in plain text then tell me if it is there; However, I need it to change part of the URL if it doesn't find anything, and then reload the page and search again. Basically like

"http://www.youtube.com/watch=?55555"
it would search for say the word "bunnies". if it doesnt find the word on there then it adds one to the "55555" to make it "55556" and then searches that page, so on and so on.

Here is what i have so far.

url = "www.example.com/55555"
phrase = "Bunnies"

'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


所以基本上我需要做的就是不断循环,直到找到"Bunnies"为止。在页面上。我还需要确保它停在一个合理的数字,以便它不会崩溃我的电脑大声笑。我也很感激,如果它告诉我它找到了什么URL。

So Basically all i need that to do is loop continuously until it finds "Bunnies" on the page. I also need to make sure it stops at a reasonable number so that it doesnt crash my pc lol. I would also appreciate if it tells me what URL it found it on.

推荐答案

当你麻烦给代码一些结构时并且使用良好的缩进然后练习变得几乎无足轻重:

When you take the trouble to give the code some structure and use good indentation then the exercise becomes almost trivial:

iStart = 55555
bFound = False
phrase = "Bunnies"
For i = iStart To iStart + 20 GetData i if bFound then Exit For Next Sub GetData(x) url = "www.example.com/" & i '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 here: www.example.com/" & i bFound = True 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 End Sub


这篇关于VBS URL程序帮助!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆