web scraping data to dashing dashboard

349 views Asked by At

I am having trouble scraping a site to get some information. I am very green with ruby but trying to learn as much as I can. The data will be sent to a Dashing.io dashboard using a google maps widget ( https://github.com/andmcgregor/dashing-map ) to get the current location of our delivery driver. This will be on a screen in our sale office so the staff know exactly where our driver is at a glance.

I have the following code:

require 'mechanize'
require 'open-uri'
require 'restclient'

agent = Mechanize.new
agent.get('http://ilogix.capitaltransport.com.au/iLogixLogin.asp')

agent.page.forms[0]["txtUsername"] = "someusername"
agent.page.forms[0]["txtPassword"] = "somepassword"

agent.page.forms[0].submit

page = agent.get('http://ilogix.capitaltransport.com.au/Home/iLogix_AlertInformation.asp?DisplayType=Comms')

url = puts page.parser.xpath('//table/tr/td/script')

which gets me here

irb(main):014:0* url = puts page.parser.xpath('//table/tr/td/script')
<script type="text/javascript">
                        //Set Table Headers

                            var myHeaders = ["Fleet","ID", "Name","Type","Status
","Last Update","Location","Information"];


                    //Set Grid Object
                    var obj = new AW.UI.Grid;
                        obj.setId("myGrid");    // necessary for CSS rules

                    //Virtual mode
                    obj.setVirtualMode(true);   // Enable virtual mode

                    //Set Header Text
                        obj.setHeaderText(myHeaders);

                    //Set Number of Columns and their width


                            //Set the Number of columns
                            obj.setColumnCount(8);

                            //Set Column Widths
                            obj.setColumnWidth(130, 0); // set width of the column-1 Vehicle Details
                            obj.setColumnWidth(45, 1);  // set width of the column-3 Fleet
                            obj.setColumnWidth(100, 2); // set width of the column-4 ID
                            obj.setColumnWidth(100, 3); // set width of the column-5 DisplayName
                            obj.setColumnWidth(100, 4); // set width of the column-6 Status
                            obj.setColumnWidth(130, 5); // set width of the column-7 Last Comms
                            obj.setColumnWidth(220, 6); // set width of the column-8 Location
                            obj.setColumnWidth(250, 7); // set width of the column-9 Bad GPS

                                                        obj.setCellText("Clutch and Brake (WA)",0,0);
                                                        obj.setCellText("7518",1 ,0);
                                                        obj.setCellText("7518",2 ,0);
                                                        obj.setCellText("Tray (1 T)",3,0);
                                                        obj.setCellText("",4,0); 
                                                        obj.setCellText("26 Jun 2015 15:51:46",5,0);
                                                        obj.setCellText("414-424 Beechboro Rd, Morley 6102",6,0);
                                                        obj.setCellText(":: since last Communication Activity",7,0);

                    //number of rows and Height
                    obj.setRowCount(1);
                    obj.setRowHeight(20);

                    //Write Object to the Screen
                    document.write(obj);

                    </script>
=> nil
irb(main):015:0>

What I would like is to pull just the location string. I just cant figure it out. After that I think I will need to find a way to convert that to lat and long for use with the widget but I think this http://www.rubygeocoder.com/ will do it.

Here is the html. If someone can help or point me in the right direction I would really appreciate it because I am truly stuck. Thanks.

    <html class=" aw-all aw-quirks aw-vista aw-png2" xmlns="http://www.w3.org/1999/xhtml">

    <head></head>
    <body class="Body">
        <table cellspacing="0" cellpadding="0" border="0" align="center" style="width:100%;height:100%">
            <tbody>
                <tr style="height:100%">
                    <td>
                        <script type="text/javascript"></script>
                        <span id="myGrid" class="aw-system-control aw-grid-control aw-selectors-hidden " onselectstart="return false" oncontextmenu="AW(this,event)" hidefocus="true" tabindex="-1">

    <span id="myGrid-box" class="aw-grid-box " onactivate="AW(this,event)">
        <textarea id="myGrid-box-focus" class="aw-control-focus " onpaste="AW(this,event)" oncopy="AW(this,event)" oncut="AW(this,event)" onbeforecopy="AW(this,event)" onselectstart="AW(this,event)" onbeforedeactivate="AW(this,event)" tabindex="0"></textarea>

<span id="myGrid-scroll" class="aw-scroll-bars aw-scrollbars-none " onmousewheel="AW(this,event)" onresize="AW(this,event)" style="visibility: inherit;">

    <span id="myGrid-scroll-box" class="aw-bars-box " onscroll="AW(this,event)"></span>

<span id="myGrid-scroll-content" class="aw-bars-content " style="right: 17px; bottom: 17px;">

    <span id="myGrid-view" class="aw-hpanel-template ">
        <span id="myGrid-view-box" class="aw-hpanel-box ">
            <span id="myGrid-view-box-top" class="aw-hpanel-top " style="height:20px;visibility:inherit;"></span>
            <span id="myGrid-view-box-middle" class="aw-hpanel-middle " style="top:20px;bottom:0px;">
                <span id="myGrid-rows" class="aw-templates-list aw-grid-view ">
                    <span id="myGrid-rows-start" class="aw-view-top " style="height:0px;"></span>
                    <span id="myGrid-row-0" class="aw-templates-list aw-text-normal aw-grid-row aw-row-0 aw-rows-normal aw-alternate-even ">
                        <span id="myGrid-row-0-start" class="aw-row-start " style="width:0px;"></span>
                        <span id="myGrid-cell-0-0" class="aw-item-template aw-templates-cell aw-grid-cell aw-column-0 aw-cells-normal " title=""></span>
                        <span id="myGrid-cell-1-0" class="aw-item-template aw-templates-cell aw-grid-cell aw-column-1 aw-cells-normal " title=""></span>
                        <span id="myGrid-cell-2-0" class="aw-item-template aw-templates-cell aw-grid-cell aw-column-2 aw-cells-normal " title=""></span>
                        <span id="myGrid-cell-3-0" class="aw-item-template aw-templates-cell aw-grid-cell aw-column-3 aw-cells-normal " title=""></span>
                        <span id="myGrid-cell-4-0" class="aw-item-template aw-templates-cell aw-grid-cell aw-column-4 aw-cells-selected " title=""></span>
                        <span id="myGrid-cell-5-0" class="aw-item-template aw-templates-cell aw-grid-cell aw-column-5 aw-cells-normal " title=""></span>
                        <span id="myGrid-cell-6-0" class="aw-item-template aw-templates-cell aw-grid-cell aw-column-6 aw-cells-normal " title=""></span>
                        <span id="myGrid-cell-7-0" class="aw-item-template aw-templates-cell aw-grid-cell aw-column-7 aw-cells-normal " title=""></span>

                                                                <span id="myGrid-cell-8-0" class="aw-item-template aw-templates-cell aw-grid-cell aw-column-8 aw-cells-normal " title=""></span>
                                                                <span id="myGrid-row-0-end" class="aw-item-template aw-grid-cell aw-column-space "></span>
                                                            </span>
                                                            <span id="myGrid-rows-end" class="aw-item-template aw-row-selector aw-selector-space "></span>
                                                        </span>
                                                    </span>
                                                    <span id="myGrid-view-box-bottom" class="aw-hpanel-bottom " style="height:0px;display:none;"></span>
                                                </span>
                                            </span>
                                        </span>
                                    </span>
                                    <span id="myGrid-box-sample" class="aw-row-sample aw-grid-row "></span>
                                </span>
                            </span>
                        </td>
                    </tr>
                </tbody>
            </table>
        </body>
    </html>
0

There are 0 answers