2016-08-28 192 views
1

This is an screenshot of siteJsoup HTML代碼解析

我用下面的代碼

 @Override 
    protected Void doInBackground(Void... params) { 
     try { 
      Connection.Response baglanilan = Jsoup.connect("http://www.eshot.gov.tr/tr/UlasimSaatleri/288") 
        .method(Connection.Method.GET) 
        .execute(); 
      Document document = Jsoup.connect("http://www.eshot.gov.tr/tr/UlasimSaatleri/288").data("hatId","581").cookies(baglanilan.cookies()).post(); 

       Elements bakiye = document.select("#frmDuraklar > ul > li"); 
       veri1ad = bakiye.toString(); 

     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
     return null; 
    } 
    @Override 
    protected void onPostExecute(Void result) { 
     super.onPostExecute(result); 
     progressDialog.dismiss(); 
     tvveri.setText(veri1ad); 
    } 

代碼獲得:

<li class="ring" id="10504">Fahrettin Altay</li> 
<li class="ring" id="10507">İkinci Oyak Sitesi</li> 
<li class="ring" id="10505">Ordu Pazarı</li> 
<li class="ring" id="10506">Mehmet&ccedil;ik</li> 
. 
. 
. 

我需要的結果只有ID列表。我如何解析一個id列表?

+0

什麼反應「bakiye」? –

回答

1

你幾乎接近輸出有忘了重複的元素

try { 
      Connection.Response baglanilan = Jsoup.connect("http://www.eshot.gov.tr/tr/UlasimSaatleri/288") 
        .method(Connection.Method.GET) 
        .execute(); 
      Document document = Jsoup.connect("http://www.eshot.gov.tr/tr/UlasimSaatleri/288").data("hatId","581").cookies(baglanilan.cookies()).post(); 


      Elements elements = document.select("#frmDuraklar > ul > li"); 

      for (Element element : elements) { 
       System.out.println(element.attr("id")); 
      } 



     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
+0

坦克你終於工作:) – Tornavidas