Question

I have parsed the first table but I don't know how to parse the second table.

    <div class="catItemHeader" style="position: absolute;">
    <h3 class="catItemTitle" style="color: #982C37;font-size: 30px;font-weight: 600;">Arrivi</h3>

    <div style="color: #982C37; margin-left: 104px;margin-top: -20px;font-weight: bold;">
        <label>Ultimo aggiornamento:</label> 17/04/2014 10:12   </div>
    <table class="tabella-voli">
        <thead>
            <th>Compagnia</th>
            <th>N.</th>
            <th>Provenienza</th>
            <th>Schedulato</th>
            <th>Stimato</th>
            <th>Stato</th>
        </thead>
        <tbody>
                        <tr style="background-color: rgba(253, 253, 253, 0.8);">
                <td>RYANAIR</td>
                <td>03071</td>
                <td>Londra Stansted</td>
                <td>17/04/2014 12:40</td>
                <td>17/04/2014 12:32</td>
                <td>
                                        <img src="/images/volo_green.gif"  alt="In orario" title="In orario"/><br /> In orario              </td>
            </tr>
                        <tr style="background-color: rgba(253, 253, 253, 0.8);">
                <td>RYANAIR</td>
                <td>04075</td>
                <td>Kaunas</td>
                <td>17/04/2014 16:10</td>
                <td>17/04/2014 16:10</td>
                <td>
                                        <img src="/images/volo_green.gif"  alt="In orario" title="In orario"/><br /> In orario              </td>
            </tr>
                        <tr style="background-color: rgba(253, 253, 253, 0.8);">
                <td>RYANAIR</td>
                <td>07316</td>
                <td>Dublino</td>
                <td>17/04/2014 20:45</td>
                <td>17/04/2014 20:45</td>
                <td>
                                        <img src="/images/volo_green.gif"  alt="In orario" title="In orario"/><br /> In orario              </td>
            </tr>
                    </tbody>
    </table>
</div>


<div class="catItemHeader" style="margin-left: 438px;">
    <h3 class="catItemTitle" style="color: #982C37;font-size: 30px;font-weight: 600;">Partenze</h3>

    <div style="color: #982C37;margin-left: 158px;margin-top: -20px;font-weight: bold;">
        <label>Ultimo aggiornamento:</label> 17/04/2014 10:12   </div>
    <table class="tabella-voli">
        <thead>
            <th>Compagnia</th>
            <th>N.</th>
            <th>Destinazione</th>
            <th>Schedulato</th>
            <th>Stimato</th>
            <th>Stato</th>
        </thead>
        <tbody>
                        <tr style="background-color: rgba(253, 253, 253, 0.8);">
                <td>RYANAIR</td>
                <td>03074</td>
                <td>Londra Stansted</td>
                <td>17/04/2014 13:05</td>
                <td>17/04/2014 13:05</td>
                <td>
                                        <img src="/images/volo_green.gif" alt="In orario" title="In orario"/><br /> In orario               </td>
            </tr>
                        <tr style="background-color: rgba(253, 253, 253, 0.8);">
                <td>RYANAIR</td>
                <td>04076</td>
                <td>Kaunas</td>
                <td>17/04/2014 16:35</td>
                <td>17/04/2014 16:35</td>
                <td>
                                        <img src="/images/volo_green.gif" alt="In orario" title="In orario"/><br /> In orario               </td>
            </tr>
                        <tr style="background-color: rgba(253, 253, 253, 0.8);">
                <td>RYANAIR</td>
                <td>07317</td>
                <td>Dublino</td>
                <td>17/04/2014 21:10</td>
                <td>17/04/2014 21:10</td>
                <td>
                                        <img src="/images/volo_green.gif" alt="In orario" title="In orario"/><br /> In orario               </td>
            </tr>
                    </tbody>
    </table>
</div>

 </div>
            </div>
                </div>

</div>

The first table parsed with:

org.jsoup.nodes.Document doc = Jsoup.connect("http://site.eu").timeout(7*1000).get();

org.jsoup.nodes.Element tabella = doc.getElementsByClass("tabella-voli").first();
Iterator<org.jsoup.nodes.Element> iterator = tabella.select("td").iterator();

while(iterator.hasNext()){

Can you help me with parsing ONLY the second table? I want only td elements.

Était-ce utile?

La solution

You can instantiate an Elements class instead on directly invoque "first()" on it. Then you will be able to parse the table you wish with the "get(int)" method:

Elements tables = currentServerPage.getElementsByClass("tabella-voli");
Element secondTable = tables.get(1);
Elements tdElements = currentServerPage.getElementsByTag("td");

Then you'll get a list of Elements, containing all the "td" in the second table.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top