需要帮助解析此表

public String getTotalInfected() {
    try {
        Document doc = Jsoup.parse("<tr class=\"total_row_world odd\" role=\"row\">\r\n" + 
                "<td></td>\r\n" + 
                "<td style=\"text-align:left;\">World</td>\r\n" + 
                "<td class=\"sorting_1\">4,815,439</td>\r\n" + 
                "<td>+16,173</td>\r\n" + 
                "<td>316,853</td>\r\n" + 
                "<td>+333</td>\r\n" + 
                "<td>1,863,306</td>\r\n" + 
                "<td>2,635,280</td>\r\n" + 
                "<td>44,817</td>\r\n" + 
                "<td>618</td>\r\n" + 
                "<td>40.6</td>\r\n" + 
                "<td></td>\r\n" + 
                "<td></td>\r\n" + 
                "<td></td>\r\n" + 
                "<td style=\"display:none\" data-continent=\"all\">All</td>\r\n" + 
                "</tr>");
        Elements tr = doc.select("tr");
        System.out.println("tr elements in html: " + tr.size());
        Elements td = tr.select("td");
       System.out.println(td.text());
        return null;

    } catch (Exception ex) {
        return "Error in website linkage";
    }
}

希望从td标签中抓取数字 由于某种原因,没有任何废品。我对JSoup库很陌生,并且报废表使我发疯。我在这里先向您的帮助表示感谢!

评论
  • 女神
    女神 回复
    import org.jsoup.Jsoup;
    

    导入org.jsoup.nodes.Document; 导入org.jsoup.select.Elements;

    公开课测试{

    public static void main(String[] args) {
          try {
                Document doc = Jsoup.parse("<tr class=\"total_row_world odd\" role=\"row\">\r\n" + 
                        "<td></td>\r\n" + 
                        "<td style=\"text-align:left;\">World</td>\r\n" + 
                        "<td class=\"sorting_1\">4,815,439</td>\r\n" + 
                        "<td>+16,173</td>\r\n" + 
                        "<td>316,853</td>\r\n" + 
                        "<td>+333</td>\r\n" + 
                        "<td>1,863,306</td>\r\n" + 
                        "<td>2,635,280</td>\r\n" + 
                        "<td>44,817</td>\r\n" + 
                        "<td>618</td>\r\n" + 
                        "<td>40.6</td>\r\n" + 
                        "<td></td>\r\n" + 
                        "<td></td>\r\n" + 
                        "<td></td>\r\n" + 
                        "<td style=\"display:none\" data-continent=\"all\">All</td>\r\n" + 
                        "</tr>");
    
                Elements tr = doc.select("body");
    
               System.out.println(tr.text());
    
    
            } catch (Exception ex) {
    
            }
    }
    

    }

    我把它修好了!