• You've been granted Beta access to this site, allowing you to explore some of the new features while they're still under construction. More information can be found in the Beta forum.

Need Scipting help!

Squintz

Senior Member
http://www.chart.state.md.us/travinfo/dmsSigns.asp

I am trying to scrape the messages displayed on maryland road signs. So far I have it narrowed down to a bunch of images who have their alpha equilvalent stored in the alt of the HTML. For example...

Code:
<img src="/images/dms/S.gif" alt="S">

now after I scrape the site I have a whole crap load of images which I should be able to loop through one at a time and extract the alt value and make a nice little text version of the sign to store in homeseer. Here is an example of the data i want to loop through.

Code:
<IMG SRC="/images/dms/beacon.gif" ALT="flashing beacon"><BR><img src="/images/dms/A.gif" alt="A"><img src="/images/dms/C.gif" alt="C"><img src="/images/dms/C.gif" alt="C"><img src="/images/dms/I.gif" alt="I"><img src="/images/dms/D.gif" alt="D"><img src="/images/dms/E.gif" alt="E"><img src="/images/dms/N.gif" alt="N"><img src="/images/dms/T.gif" alt="T"><img src="/images/dms/space.gif" alt=" "><img src="/images/dms/J.gif" alt="J"><img src="/images/dms/E.gif" alt="E"><img src="/images/dms/R.gif" alt="R"><img src="/images/dms/S.gif" alt="S"><img src="/images/dms/E.gif" alt="E"><img src="/images/dms/Y.gif" alt="Y"><img src="/images/dms/space.gif" alt=" "><img src="/images/dms/T.gif" alt="T"><img src="/images/dms/P.gif" alt="P"><img src="/images/dms/K.gif" alt="K"><img src="/images/dms/E.gif" alt="E"><BR><img src="/images/dms/C.gif" alt="C"><img src="/images/dms/L.gif" alt="L"><img src="/images/dms/O.gif" alt="O"><img src="/images/dms/S.gif" alt="S"><img src="/images/dms/E.gif" alt="E"><img src="/images/dms/D.gif" alt="D"><img src="/images/dms/space.gif" alt=" "><img src="/images/dms/A.gif" alt="A"><img src="/images/dms/T.gif" alt="T"><img src="/images/dms/space.gif" alt=" "><img src="/images/dms/E.gif" alt="E"><img src="/images/dms/X.gif" alt="X"><img src="/images/dms/I.gif" alt="I"><img src="/images/dms/T.gif" alt="T"><img src="/images/dms/space.gif" alt=" "><img src="/images/dms/5.gif" alt="5"><BR><img src="/images/dms/U.gif" alt="U"><img src="/images/dms/S.gif" alt="S"><img src="/images/dms/E.gif" alt="E"><img src="/images/dms/space.gif" alt=" "><img src="/images/dms/A.gif" alt="A"><img src="/images/dms/L.gif" alt="L"><img src="/images/dms/T.gif" alt="T"><img src="/images/dms/space.gif" alt=" "><img src="/images/dms/I.gif" alt="I"><img src="/images/dms/dash.gif" alt="-"><img src="/images/dms/2.gif" alt="2"><img src="/images/dms/9.gif" alt="9"><img src="/images/dms/5.gif" alt="5"><img src="/images/dms/space.gif" alt=" "><img src="/images/dms/O.gif" alt="O"><img src="/images/dms/R.gif" alt="R"><img src="/images/dms/space.gif" alt=" "><img src="/images/dms/I.gif" alt="I"><img src="/images/dms/dash.gif" alt="-"><img src="/images/dms/9.gif" alt="9"><img src="/images/dms/5.gif" alt="5">

This says "ACCIDENT JERSEY TPKE CLOSED AT EXIT 5 USE ALT I-295 OR I-95"

So I need a loop that will go through and get each alt="VALUE" and store the value into a string. Problem is that if you notice that sometimes the first value is simply a picture and not a alpha/numeric character. I would like to check for this. Also the size of the sign changes so I would need a loop that varies in size.

Here is the page i am trying to scrape:
http://www.chart.state.md.us/travinfo/dmsSigns.asp

EDITED: Second bit of code was not accurate. Updated it so not to confuse anyone.
 

Rupp

Senior Member
Squintz,
Can you post what you have so I can see if there's a good point to parse it as it runs.
 

Rupp

Senior Member
Squintz,
Are you storing all these images in device code? I can't really run the code because it appears to scraping is already done.
 

Rupp

Senior Member
Here's a small sniplet to stip the alt tag out of a string. The problem is you can't assign your img tags to strings because of the "" in the strings.


Code:
sData = "<IMG SRC=""/images/dms/beacon.gif"" ALT=""flashing beacon"">"
iStart = InStrRev(sData, "ALT")
sDesiredData = Mid(sData, iStart + 5)
sDesiredData = Replace(sDesiredData, """>", "")
 

Squintz

Senior Member
Rupp,

Im on the cocoon chat right now and will be on all night if you wish to chat live.

In order to run the script in its current state you need to first create a virtual device with the following settings.

Device Type: Road Sign
Device Name: I-95 South prior to Ex. 33 MD 198 Sign# 320

The Device name can be anything under the location column on http://www.chart.state.md.us/travinfo/dmsSigns.asp

Once you run the script now you will get alot of errors from it trying to load the pictures but the plugin should already grab the data that i need to loop through.
 

Squintz

Senior Member
it seems that i have mor problems with my script but that is expected right now. This is my very first draft of it. Seems its not finding the location text on the page for some reason
 

Rupp

Senior Member
After adding this line of code under
Code:
strStatus = GetSignData(dv.Name)
        sData = ParseData(strStatus)  ' new line

Function ParseData(sInput)
  sDesiredData = ""
  sSplData = Split(sInput, "alt")

  For i = 1 To UBound(sSplData)
      sDesiredData = sDesiredData & Mid(sSplData(i), 3, 1)
  Next
End Function

The sData will be your data....

G
 

Squintz

Senior Member
here is what i have so far rupp.. still a little bit of error but its working sorta.
 

Attachments

  • roadsigns.txt
    2.1 KB · Views: 25

Rupp

Senior Member
Code:
Function ParseData(sInput)

sDesiredData = ""
sSplData = Split(sInput, "alt")

For i = 1 To UBound(sSplData)
    sDesiredData = sDesiredData & Mid(sSplData(i), 3, 1)
    If InStr(1, sSplData(i), "<BR>") Then
        sDesiredData = sDesiredData & " "
    End If
Next

ParseData = sDesiredData

End Function
 
Top