Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Searching a webpage for a specific phrase?

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,62795
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Searching a webpage for a specific phrase?
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Searching a webpage for a specific phrase? - 7/26/2008 12:55:43 PM   
  Weedhopper

 

Posts: 5
Score: 0
Joined: 7/26/2008
Status: offline
I'm trying to write a script that will search a webpage for the sentence "We're sorry." and then email me if that phrase is not found. Being a newbie who is working off of someone elses half-completed script I was happy to get most of it working, but I seem to be stuck here. This is what I have so far:

strURL = "http://www.sample.com"
Set objHTTP = CreateObject("MSXML2.XMLHTTP")
Call objHTTP.Open("GET", strURL, FALSE)
objHTTP.Send

strHTML = objHTTP.ResponseText

instock = InStr(strHTML, "We're sorry.")

wscript.sleep 10000 'time in milliseconds between checks'
counter = counter + 1




if instock=0 then
'Sends email'
 
 
Post #: 1
 
 RE: Searching a webpage for a specific phrase? - 7/26/2008 1:41:06 PM   
  dm_4ever


Posts: 2669
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Did you try

if instock > 0 then
'Sends email'

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Weedhopper)
 
 
Post #: 2
 
 RE: Searching a webpage for a specific phrase? - 7/26/2008 3:13:51 PM   
  Weedhopper

 

Posts: 5
Score: 0
Joined: 7/26/2008
Status: offline
Just tried that and it didnt change a thing :(

The problem seems to be that Instock is always 0 no matter if "We're sorry." is on the page or not. So it doesnt appear that the code is even detecting the phrase correctly...

(in reply to dm_4ever)
 
 
Post #: 3
 
 RE: Searching a webpage for a specific phrase? - 7/26/2008 3:30:47 PM   
  dm_4ever


Posts: 2669
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Have you echoed out the content of strHTML to exactly what is shown?  Is the case the same?

strHTML = objHTTP.ResponseText
WScript.Echo strHTML

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Weedhopper)
 
 
Post #: 4
 
 RE: Searching a webpage for a specific phrase? - 7/26/2008 4:28:10 PM   
  fosterr_2000

 

Posts: 115
Score: 0
Joined: 12/18/2004
From:
Status: offline
This may seem too obvious but shouldn't the "IF" statement have and "End IF"?

Also I agree with dm_4ever, it should be > 0.  The instr will return a positive integer representing the position of the first character if it exist in the string and 0 if it is not found, therefore it should email if > 0.

Also you might try echoing out a message just to see if your if test is working properly.  If so then it might be your email function.  If so I have a good email function I will share if you would like.


if instock > 0 then
  wscript.echo "Found the String"
end if



Hope this helps.

(in reply to Weedhopper)
 
 
Post #: 5
 
 RE: Searching a webpage for a specific phrase? - 7/26/2008 4:33:04 PM   
  Weedhopper

 

Posts: 5
Score: 0
Joined: 7/26/2008
Status: offline
I tried echoing it, that just gave me a long bar with the minimize, maximize and close buttons on it. I then tried displaying it through a msgbox and was able to see a bit of HTML from the page, but it was cut off after a few lines. I'm not sure if that is just a restriction of msgbox though.

(in reply to dm_4ever)
 
 
Post #: 6
 
 RE: Searching a webpage for a specific phrase? - 7/26/2008 4:42:26 PM   
  Weedhopper

 

Posts: 5
Score: 0
Joined: 7/26/2008
Status: offline
Oops, yah there is an End if at the very bottom of the code. Oh and email is working fine, I accidently spammed myself when i was fooling around with it earlier :P Since I don't want an email when "We're sorry." is found I want instock to equal zero, correct?

(in reply to fosterr_2000)
 
 
Post #: 7
 
 RE: Searching a webpage for a specific phrase? - 7/26/2008 4:57:47 PM   
  fosterr_2000

 

Posts: 115
Score: 0
Joined: 12/18/2004
From:
Status: offline
I used www.intel.com to test this and it seem to work.


strURL = "http://www.intel.com"
Set objHTTP = CreateObject("MSXML2.XMLHTTP")
Call objHTTP.Open("GET", strURL, FALSE)
objHTTP.Send
strHTML = objHTTP.ResponseText
instock = InStr(lcase(strHTML), "please choose your location.")

if instock > 0 then
wscript.echo "Found the String at " & instock & " position."
else
wscript.echo "Not Found."
end if


Also keep in mind that vbscript is case sensitive so I often force everything to lower case before I do any kind of compare:

For example:  instock = InStr(lcase(strHTML), "please choose your location.")


Hope this helps.

(in reply to Weedhopper)
 
 
Post #: 8
 
 RE: Searching a webpage for a specific phrase? - 7/27/2008 3:56:32 AM   
  Weedhopper

 

Posts: 5
Score: 0
Joined: 7/26/2008
Status: offline
Hmmm, I copy/pasted my url into your code and it still didn't work! No wonder why I have been so confused... something with the webpage isn't allowing the script to do its thing! Now that I'm using a slightly different URL it seems to be working just fine, thanks guys!

(in reply to fosterr_2000)
 
 
Post #: 9
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Searching a webpage for a specific phrase? Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts