Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

find a word in a webpage with vbscript?

Status
Not open for further replies.

BAMJW

Technical User
Dec 16, 2012
5
BE
Hello,

I am trying to make my life a bit easier by making a script that opens a webpage, Find certain words, if that word is found give an alert. and repeat this action every minute.


who should i do this?



thanks,

 
What have you tried so far and where in your code are you stuck ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Option Explicit
Dim ie, fill
dim txt
Set fill = CreateObject("Wscript.shell")
Set ie = CreateObject("internetExplorer.Application")

ie.visible = 1
ie.Navigate("DO while ie.Busy
Wscript.sleep 100
loop
txt="facebook"

If ie.Document.innerHTML(txt) then
msg "found it!"

end If



i am a not an expert in these things so sorry if did something stupid :)

thats the whole thing i don't know wich object i should use to find this.
 
Hi [bigglasses] Try this code :

Code:
Do
Find "facebook","[URL unfurl="true"]https://www.facebook.com"[/URL]
Pause("1")'waiting for 1 minute and repeat the action
Loop

Function Find(StrString,URL)
Titre = "Find a String in a webpage"
'URL = "[URL unfurl="true"]https://www.facebook.com"[/URL]
Set ie = CreateObject("InternetExplorer.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject") 
ie.Navigate(URL) 
ie.Visible = 1
DO WHILE ie.busy
wscript.sleep 100
LOOP
Data = ie.document.documentElement.innertext 
Set ie = Nothing
Set objRegex = new RegExp
objRegex.Pattern = StrString
objRegex.Global = False
objRegex.IgnoreCase = True
Set Matches = objRegex.Execute(Data)
For Each Match in Matches   
    MsgBox "We found this word : " &vbCr& qq(Match.Value) & "in " & URL,64,Titre 
Next
End Function

Function qq(strIn)
    qq = Chr(34) & strIn & Chr(34)
End Function

Function Pause(NbMin)
wscript.sleep NbMin*1000*60
End Function
 
Hello,


This is very good, thanks. I still need to adjust a little bit because i did not told you guys the complete story.But i can work with this, So i will now try and do my best if i get stuck i will be back thanks guys. love this kind of people.

 
Nice for someone to ask.

So the thing is like this: there is a website that refreshes every 5 minutes.
If it refreshes there are certain new errors that are being displayed.
if a error has a certain string in it, we have to get an alert.
So every time the page refreshes a script has to run and compare the previous page with the new and if in those new errors is a certain word then there must be an alert raised. And this has to been done in vbscript.

i hope i explained it good.

one thing is sure i find it difficult
 
Can you provide us the URL of the website if it isn't private of course [2thumbsup]
You can run the Internet Explorer in the background each 5 minutes like this :
Code:
Do
	Find "facebook","[URL unfurl="true"]https://www.facebook.com"[/URL]
	Pause("5")'waiting for 5 minutes and repeat the action
Loop

Function Find(StrString,URL)
	Titre = "Find a String in a webpage"
'URL = "[URL unfurl="true"]https://www.facebook.com"[/URL]
	Set ie = CreateObject("InternetExplorer.Application")
	Set objFSO = CreateObject("Scripting.FileSystemObject") 
	ie.Navigate(URL) 
	ie.Visible = false 'run ie in the background
	DO WHILE ie.busy
		wscript.sleep 100
	LOOP
	Data = ie.document.documentElement.innertext 
	Set ie = Nothing
	Set objRegex = new RegExp
	objRegex.Pattern = StrString
	objRegex.Global = False
	objRegex.IgnoreCase = True
	Set Matches = objRegex.Execute(Data)
	For Each Match in Matches   
		MsgBox "We found this word : " &vbCr& qq(Match.Value) & "in " & URL,64,Titre 
	Next
End Function

Function qq(strIn)
	qq = Chr(34) & strIn & Chr(34)
End Function

Function Pause(NbMin)
	wscript.sleep NbMin*1000*60
End Function
 
hey,

yeah the page is kind of private, its for school, sorry. the problem is not the refresh because the page already refreshes. and the page does not have to run in the background. I will try and break it up in points.

The page must be open.
the page already refreshes automatically
if the page refreshes then run the script
the script must be compare the page with the same page before the refresh
and if there is a difference. in that difference must be checked if a word(string) is in it.

i hope i explained it good.

thanks

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top