【问题标题】:Jsoup parsing error with androidandroid 的 Jsoup 解析错误
【发布时间】:2017-03-24 18:43:33
【问题描述】:

我正在使用 jsoup 从我的大学网站 (html) 读取数据以在 android 应用中显示结构化数据。

我正在使用以下代码

Elements elements=doc.getElementsByClass("maintable").get(0).getElementsByTag("table").get(0).getElementById("table3").getElementsByTag("tbody").get(0).getElementsByTag("tr");

这是我必须显示的图像 enter image description here

html代码是

<table border="0" align="center" cellpadding="0" style="width:101%;" class="maintable" id="table5">
        <tbody><tr class="parent" title="Please Click Here To View The Content">
        <td colspan="4" class="MTTD1" align="center"><b><u>Personal Details</u></b></td>

【问题讨论】:

  • 你的预期输出是什么?

标签: android jsoup


【解决方案1】:

试试这个:

public class Test
{
    public static void main(String[] args) {
        String s ="<table border=\"0\" align=\"center\" cellpadding=\"0\" style=\"width:101%;\" class=\"maintable\" id=\"table5\">\n" +
                "        <tbody><tr class=\"parent\" title=\"Please Click Here To View The Content\">\n" +
                "        <td colspan=\"4\" class=\"MTTD1\" align=\"center\"><b><u>Personal Details</u></b></td>";
        Document doc = Jsoup.parse(s);
        Element elements = doc.select("table").first();
        for (Element element :elements.select("tr")){
            System.out.println(element.text());
        }
}

输出:

Personal Details

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-12-19
  • 1970-01-01
  • 2013-08-27
  • 1970-01-01
  • 1970-01-01
  • 2013-09-21
  • 1970-01-01
相关资源
最近更新 更多