OAC Technology
asked on
Automatically parse website information to text or XML file
Hi,
We would like to automatically check this page: http://mspairport.com/msp/parking/realtimemobile.aspx every 30 minutes or so and have the terminal names and percent of available parking get parsed into an XML file or text file to the local Windows XP machine. Is there any way of doing this with basic VBScript?
Thank you
We would like to automatically check this page: http://mspairport.com/msp/parking/realtimemobile.aspx every 30 minutes or so and have the terminal names and percent of available parking get parsed into an XML file or text file to the local Windows XP machine. Is there any way of doing this with basic VBScript?
Thank you
maybe?
this pulls the whole thing, downloads it line by line, then opens it in IE,.
it will need some work to only parse the informatino you need,... then you can save it as any file you'd like,.
this pulls the whole thing, downloads it line by line, then opens it in IE,.
it will need some work to only parse the informatino you need,... then you can save it as any file you'd like,.
Const ForReading = 1
Const Forwriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
myurl = "http://mspairport.com/msp/parking/realtimemobile.aspx"
strreadfile = "c:\results.htm"
call getdata(myurl, strreadfile)
call showdata()
Sub getdata(myurl, strreadfile)
dim oie1, myvall, i
'on error resume next
Set f_w_tmp = objFSO.OpenTextFile(strreadfile, Forwriting, true)
Set oIE1 = CreateObject("InternetExplorer.Application")
oIE1.navigate myurl
oIE1.Visible = false
do while oie1.busy=true
wscript.sleep 15
loop
myvall = split(oIE1.Document.body.innerhtml, vbcrlf)
for i = 0 to ubound(myvall)
myval = myvall(i)
myval = replace(myval, "../..", "http://mspairport.com")
f_w_tmp.writeline myval
if err.number <> 0 then errlog "problem writing this: " & myvall(i) & "to a text file"
next
oIE1.quit
f_w_tmp.close
on error goto 0
Set oIE1 = nothing
End Sub
sub showdata()
dim oie1, myvall, i
Set oIE1 = CreateObject("InternetExplorer.Application")
oIE1.navigate myurl
oIE1.Visible = true
do while oie1.busy=true
wscript.sleep 15
loop
end sub
ASKER
Thanks for the responses.
Bigjokey: When I run the vbscript, a dialogue pops up with
"Invalid XML content:
Line: [32] Required attribute 'alt' is missing.
Found: <img id="refreshparkingdata1_im gLindbergh Status" class="parkimage" src="../../img/msp/parking /status/76 .gif" border="0" /><br /> "
and no data is entered into the xml file.
Thanks again
Bigjokey: When I run the vbscript, a dialogue pops up with
"Invalid XML content:
Line: [32] Required attribute 'alt' is missing.
Found: <img id="refreshparkingdata1_im
and no data is entered into the xml file.
Thanks again
Sorry, I forgot to uncomment this line. Change this line:
'objDom.validateOnParse = False
To this (rmove the leading quote)
objDom.validateOnParse = False
This prevents the parser from validating the content.
'objDom.validateOnParse = False
To this (rmove the leading quote)
objDom.validateOnParse = False
This prevents the parser from validating the content.
ASKER
Thank you! One last question: Is there a way to append the information to the xml file each time the script is run, instead of just overwriting it?
Thanks again, this really helps
Thanks again, this really helps
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you!
You need to change the "strFile1" variable at the top of the file to point to where you want the content saved.
Remove the .txt extension from the attached file and run it. Test it out and let me know how it goes.
The output file should appear as follows:
<Terminals>
<Terminal>
<Name>Lindbergh</Name>
<Percent>31</Percent>
<Description>% Available</Description>
</Terminal>
<Terminal>
<Name>Humphrey</Name>
<Percent>32</Percent>
<Description>% Available</Description>
</Terminal>
<LastRefresh>Data current as of Thursday, May 15, 2008 at 9:24 PM</LastRefresh>
</Terminals>
httpRequest.vbs.txt