2014-04-17 5 views
0

첫 번째 테이블을 구문 분석했지만 두 번째 테이블을 구문 분석하는 방법을 알지 못합니다.두 테이블을 구문 분석하는 JSOUP

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()){ 

당신이 만 두 번째 테이블을 파싱 좀 도와 수 :

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

첫 번째 표

함께 구문 분석? 나는 td 요소 만 원한다.

답변

0

대신에 직접 invoque "first()"에 요소 클래스를 인스턴스화 할 수 있습니다. 두 번째 테이블의 모든 "TD"를 포함,

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

는 그런 다음 요소의 목록을 얻을 것이다 : 그런 다음 당신은 당신이 "수 (INT)"방법으로 원하는 테이블을 구문 분석 할 수있을 것입니다.

+0

예, 감사합니다 ...하지만 iterator 사용 ??? – roxdragon

+0

"td"목록에서 반복자를 사용하려면 이전과 동일한 작업을 수행하면됩니다. "Iterator iterator = tdElements.iterator();" 내가 왜 당신이 절대적으로 필요로하는지 이해하지 못한다면, 콜렉션을 반복 할 수있는 많은 방법이있다 ... –

+0

iterator는 왜 좋은가? – roxdragon

관련 문제