Link to home
Start Free TrialLog in
Avatar of jcneil4
jcneil4

asked on

Use IE to call up a URL and search for a specific string in the response

Ok- Here goes.  Is it possible to create a vbscript that will call up a URL using "iexplore.exe www.website.com" and search the response for a string?  I ask this because I have a database engine that connects our online store with the backend DB.  This is an active page (ASP) and my server monitoring software uses WINHttp, which gets the "unsupported browser" message response.  The server monitor software supports the use of vbscripts- but I am not a programmer...
Avatar of Marv-in
Marv-in

1. create a asp page on your server

<--start page.asp-->
<%
var objXML = new ActiveXObject("Msxml2.XMLHTTP");
objXML.open("GET", "http://www.website.com", false);
objXML.send();
strDocument = objXML.ResponseText

strWhatYourLookingFor="this is what i want to match"

if instr(strDocument,strWhatYourLookingFor) then
  '//do what you need to
else
  '//do somthing when it doesnt match
endif
%>
<--end page.asp-->

then you can setup a scheduled task in windows to launch iexplorer http://yousite/page.asp

I will need more info on what you want to do if the string is matched or not to finish the code
Avatar of jcneil4

ASKER

Ok, this may work.  I'm not sure what I want to happen but lets start with something simple like have our asp page display "the site is running" or "the site is down".   I'll have to test it in our enviornment with my server monitor software-
Thanks for the quick response.
<%
var objXML = new ActiveXObject("Msxml2.XMLHTTP");
objXML.open("GET", "http://www.website.com", false);
objXML.send();
strDocument = objXML.ResponseText

strSearch="site is up" 'this string will need to be the exact text you are looking for at www.website.com

if instr(strDocument,strSearch) then
  response.write("your site is up")
else
  response.write("your site is down")
endif
%>
Avatar of jcneil4

ASKER

When I call up the page in a IE I get --HTTP 500 - Internal server error Internet Explorer--
Here is the code I am using...


<--start sitecheck.asp-->

<%
var objXML = new ActiveXObject("Msxml2.XMLHTTP");
objXML.open("GET", "http://www.mysite.com", false);
objXML.send();
strDocument = objXML.ResponseText

strSearch="Products and Services"

if instr(strDocument,strSearch) then
  response.write("your site is up")
else
  response.write("your site is down")
endif
%>

<--end sitecheck.asp-->
could you turn off friendly errors in IE [tools -> internet options -> advanced tab] and post the exact error you recieve.
Avatar of jcneil4

ASKER

Microsoft VBScript compilation error '800a0401'

Expected end of statement

/admin/sitecheck.asp, line 4

var objXML = new ActiveXObject("Msxml2.XMLHTTP");
------------------------------^
Set objXML = Server.CreateObject("MSXML2.XMLHTTP")
Avatar of jcneil4

ASKER

Microsoft VBScript compilation error '800a0414'

Cannot use parentheses when calling a Sub

/admin/sitecheck.asp, line 6

objXML.open("GET", "http://www.mysite.com", false);
--------------------------------------------------^
Set objXML = Server.CreateObject("MSXML2.XMLHTTP")
call objXML.open("GET", "http://www.mysite.com", false);
call objXML.send;
strDocument = objXML.ResponseText

this code should will work - i tested it this time
Avatar of jcneil4

ASKER

We are getting there...

Microsoft VBScript compilation error '800a0401'
Expected end of statement
/admin/sitecheck.asp, line 6
call objXML.open("GET", "http://www.mysite.com", false);
-------------------------------------------------------^
Set objXML = Server.CreateObject("MSXML2.XMLHTTP")
call objXML.open("GET", "http://www.mysite.com", false)
call objXML.send
strDocument = objXML.ResponseText

remove the semicolons - as doesnt use them - i must have java on the brain =]
Avatar of jcneil4

ASKER

we are close..
__________________________________
Microsoft VBScript compilation error '800a0400'
Expected statement
/admin/sitecheck.asp, line 17
endif
^
_____________________________________
here is what we have so far-

<--start sitecheck.asp-->
<%
Set objXML = Server.CreateObject("MSXML2.XMLHTTP")
call objXML.open("GET", "http://www.mysite.com", false)
call objXML.send
strDocument = objXML.ResponseText
strSearch="Products and Services"
if instr(strDocument,strSearch) then
  response.write("your site is up")
else
  response.write("your site is down")
endif
%>
<--end sitecheck.asp-->



ASKER CERTIFIED SOLUTION
Avatar of Marv-in
Marv-in

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jcneil4

ASKER

OK!  It works great.  You got your points.
Thanks for the grade!!