JSoup Schleife

L

Lucius1972

Neues Mitglied
0
Guten Morgen Leute,
Ich versuche mittels JSoup mehrere Werte von einer Website zu parsen, die Seite hat folgenden Aufbau:
Code:
<tbody>
 <tr>
   <td>2015</td>
   <td>November</td>
   <td class="no-border-left"></td>
   <td class="no-border-left">&euro; 15,90</td>
   <td>
   <a href="/Invoice/Download?invoiceNo=2632992" target="_blank"><img alt="" src="/Content/Images/pdf_icon.png" /></a>                                </td>

  </tr>
  <tr>
   <td>2015</td>
   <td>Oktober</td>
   <td class="no-border-left"></td>
   <td class="no-border-left">&euro; 16,20</td>
   <td>
   <a href="/Invoice/Download?invoiceNo=2445473" target="_blank"><img alt="" src="/Content/Images/pdf_icon.png" /></a> 
   </td>   
 </tr>
       ....
</tbody>

Ich brauchte alle Werte von Jahr (2015), Monat (November), Betrag (&euro; 15,90) und Link (a href).
Ich habe schon ein wenig mit JSoup rumgebastelt und probiert dies mittels Schleife hinzubekommen aber bekomme es nicht richtig hin.

Wenn Jemand helfen koennte, wer das Klasse.
Danke euch.

Mein Code bis jetzt:

Code:
....   
 Elements Tbody = doc.select("TBODY");
   for (Element p : Tbody) {

   Iterator<Element> postIt = p.select("td").iterator();
      String YeaR = postIt.next().text();
      String MontH = postIt.next().text();

      postIt.next();
      postIt.next();

        Element amount = doc.select("td.no-border-left").first();
          String amounT = amount.text();

         Element hrefs = doc.select("a[href]").first();
           String linK = hrefs.text();
   }
  ....
 
@markus.tullius, Danke dir.
Ich habe es hingekriegt, folgender Code:

Code:
try {
     CharSequence cs1 = "€";

     is = getActivity().getAssets().open("test.htm");
     Document doc = Jsoup.parse(is, "UTF-8", "http://example.com/");
     Elements rows = doc.select("tr");

        for (int i = 1; i < rows.size(); i++) {

         Element row = rows.get(i);
         Elements cols = row.select("td");
         Elements links = row.getElementsByTag("a");

         String YeaR = cols.get(0).text();
         //Log.e("JSOUP: ", YeaR);
         String MontH = cols.get(1).text();
         //Log.e("JSOUP: ", MontH);

            for (Element tes : cols)
                 if (tes.text().contains(cs1)) {
                     String amounT = tes.text();
                     //Log.e("JSOUP: ", amounT);
                 }
                    for (Element link : links) {
                        String url = link.attr("href");
                        //Log.e("JSOUP: ", url);
                    }
            }

            if (is != null)
                is.close();

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

Ergibt:

Code:
E/JSOUP:: 2015
 E/JSOUP:: November
 E/JSOUP:: € 15,90
 E/JSOUP:: /Invoice/Download?invoiceNo=2632992
 E/JSOUP:: 2015
 E/JSOUP:: Oktober
 E/JSOUP:: € 16,20
 E/JSOUP:: /Invoice/Download?invoiceNo=2445473
 

Ähnliche Themen

M
Antworten
4
Aufrufe
1.168
swa00
swa00
5
Antworten
0
Aufrufe
1.141
586920
5
B
Antworten
4
Aufrufe
470
bb321
B
Zurück
Oben Unten