简体   繁体   English

JSOUP解析多行

[英]JSOUP parsing for multiple rows

I am trying to parse information from a particular website using JSOUP. 我正在尝试使用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". 到目前为止,我可以解析并显示一行,因为该网站上有很多html,而我对此很陌生,我想知道是否有一种方法可以解析包含“ 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 . 这将返回所有具有以fixturerow开头的id的元素。

You may have better luck if you use a selector that looks for id's that start-with the text of interest. 如果使用选择器查找以感兴趣的文本开头的 id,则可能会更好。 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. ^=表示感兴趣的文本以其后的文本开头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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