【问题标题】:Parsing table html using JSoup使用JSoup解析表格html
【发布时间】:2015-10-11 03:58:50
【问题描述】:

对不起我的英语。我使用jsop 库并尝试从表中解析数据。但我没有好的结果。我有这个 html:

<table class="charTable">
<tr>
<th><a href="processor.html">№</a></th>
<th><a href="processor_model.html" >Модель</a></th>
</tr>
<tr valign=top  style="background-color:#FFFFFF">
<td><nobr><input type="checkbox" name="887" class="compare_check">1</nobr></td>
<td><nobr><b><a href="./processor_887.html">Intel Core i7-4940MX (Haswell)</a></b></nobr></td><td>3100</td>
</tr>
<tr>.....</tr>
<tr>.....</tr>
<tr>.....</tr>
<tr>.....</tr>
</table >

我需要这个字符串:

Intel Core i7-4940MX (Haswell)

我喜欢这样:

Elements text = doc.select("tbody > tr > td > nobr > b > a");

然后他输出了我

<a href="./processor_887.html">Intel Core i7-4940MX (Haswell)</a>

【问题讨论】:

  • "... > b > a").first().text() 工作?
  • @Tim 是的,谢谢。我确实喜欢这个doc.select("tbody &gt; tr &gt; td &gt; nobr &gt; b &gt; a").first().toString(),但它只输出一次。我认为我需要获取元素并获取该元素。我会试试的
  • 啊,好的。所以通过文本迭代,应该工作。 for (元素 e: text) System.out.println(e.text());
  • np,如果对你有用,请接受答案

标签: android html parsing


【解决方案1】:

使用Element类的text()方法抓取节点值文本。

例如 for (元素 e: text) { System.out.println(e.text()); }

【讨论】:

    猜你喜欢
    • 2014-01-01
    • 2019-10-10
    • 2015-08-17
    • 2018-09-04
    • 2015-10-14
    • 2011-07-20
    相关资源
    最近更新 更多