网页抓取数据到仪表板

时间:2015-06-26 08:19:37

标签: ruby web-scraping mechanize dashing

我在抓取网站以获取某些信息时遇到问题。我对红宝石非常环保,但我尽可能多地学习。数据将使用Google地图窗口小部件(https://github.com/andmcgregor/dashing-map)发送到Dashing.io信息中心,以获取我们的送达驱动程序的当前位置。这将在我们的销售办公室的屏幕上显示,以便工作人员确切知道我们的司机在哪里一目了然。

我有以下代码:

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')

让我来到这里

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>

我想要的是仅拉出位置字符串。我只是想不通。在那之后我想我需要找到一种方法将其转换为lat并且很长时间用于小部件,但我认为http://www.rubygeocoder.com/会这样做。

这是html。如果有人可以帮助或指出我正确的方向,我会非常感激,因为我真的被卡住了。感谢。

    <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 个答案:

没有答案