简体   繁体   中英

JSOUP parsing for multiple rows

I am trying to parse information from a particular website using JSOUP. So far I can parse and display a single row, as the website has a lot of html and I am quite new to this I was wondering is there a way to parse all table rows on the page containing the word "fixturerow".

Here is my parser code:

 Document doc =Jsoup.connect("http://www.irishrugby.ie/club/ulsterbankleagueandcup/fixtures.php").get();
  Elements kelime = doc.select("tr#fixturerow0");
    for(Element sectd:kelime){
        Elements tds = sectd.select("td"); 

              String result = tds.get(0).text();
               String result1 = tds.get(1).text();
               String result2 = tds.get(2).text();
               String result3 = tds.get(3).text();
               String result4 = tds.get(4).text();
               String result5 = tds.get(5).text();
               String result6 = tds.get(6).text();
               String result7 = tds.get(7).text();


               System.out.println("Date: " + result);
               System.out.println("Time: " + result1);
               System.out.println("League: " + result2);
               System.out.println("Home Team: " + result3);
               System.out.println("Score: " + result4);
               System.out.println("Away Team: " + result5);
               System.out.println("Venue: " + result6);
               System.out.println("Ref: " + result7);

    }` 

Thanks for your time!

You can use the ^= (starts-with) selector:

Elements kelime = doc.select("tr[id^=fixturerow]");

This will return all elements with an id that starts with fixturerow .

You may have better luck if you use a selector that looks for id's that start-with the text of interest. So try changing

Elements kelime = doc.select("tr#fixturerow0");

to

Elements kelime = doc.select("tr[id^=fixturerow]");

Where ^= means that the text of interest starts with the text that follows.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM