JSoup 无法解析 tr 标签。

huangapple go评论97阅读模式
英文:

JSoup couldn't parse tr tag

问题

我正在尝试将字符串值解析为JSoup文档,如下所示:

  1. String value = "<tr> <td>Value</td>> </tr>";
  2. Document htmlDoc = Jsoup.parse(parseTrxRawToHtml);
  3. System.out.println(htmlDoc.html());

代码执行后的结果:

  1. <html>
  2. <head></head>
  3. <body>
  4. </body>
  5. </html>

但是,似乎JSoup无法解析字符串值中的任何<tr>标签。

英文:

I am trying to parse String value to JSoup Document as follows:

  1. String value = &quot;&lt;tr&gt; &lt;td&gt;Value&lt;/td&gt;&gt; &lt;/tr&gt;&quot;;
  2. Document htmlDoc = Jsoup.parse(parseTrxRawToHtml);
  3. System.out.println(htmlDoc.html());

the result after code has been executed :

  1. &lt;html&gt;
  2. &lt;head&gt;&lt;/head&gt;
  3. &lt;body&gt;
  4. &lt;/body&gt;
  5. &lt;/html&gt;

But, it seems JSoup couldn't parsed any &lt;tr&gt; tag inside my String value.

答案1

得分: 1

显然,JSoup 无法直接解析不带外部 &lt;table&gt; 标签的 &lt;tr&gt; 标签。因此,我按照下面的方式向值中添加了 &lt;table&gt; 标签,解决了这个问题:

  1. String value = &quot;&lt;table&gt; &lt;tr&gt; &lt;td&gt;Value&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt;&quot;
英文:

Apparently JSoup couldn't parse &lt;tr&gt; tag directly without &lt;table&gt; tag outside &lt;tr&gt; tag.
So, i added &lt;table&gt; tag to the value like below and it solves the problem:

  1. String value = &quot;&lt;table&gt; &lt;tr&gt; &lt;td&gt;Value&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt;&quot;

huangapple
  • 本文由 发表于 2020年8月27日 09:07:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/63607740.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定