JSoup使用未关闭的标记解析无效的HTML [英] JSoup parsing invalid HTML with unclosed tags

查看:161
本文介绍了JSoup使用未关闭的标记解析无效的HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用JSoup(包括最后一个版本1.7.2),使用未关闭标记解析无效 HTML时出错。

Using JSoup inclusive the last release 1.7.2 there is a bug parsing invalid HTML with unclosed tags.

示例:

String tmp = "<a href='www.google.com'>Link<p>Error link</a>";
Jsoup.parse(tmp);

生成的凭证是:

<html>
 <head></head>
 <body>
  <a href="www.google.com">Link</a>
  <p><a>Error link</a></p>
 </body>
</html>

浏览器会生成以下内容:

The browsers would generate something as:

<html>
 <head></head>
 <body>
  <a href="www.google.com">Link</a>
  <p><a href="www.google.com">Error link</a></p>
 </body>
</html>

Jsoup应该作为浏览器或源代码。

Jsoup should works as browsers or as source code.

有什么解决方案吗?查看API我没有找到任何内容。

There is any solution? Looking into the API I didn't find anything.

推荐答案

正确的行为是在解析此无效HTML时充当其他浏览器。感谢您提交此错误。我已经修复了阻止采用代理商在新节点中保留原始属性的问题。它将在1.7.3中提供,或者您现在可以从头开始构建。

The correct behavior is to act as other browsers when parsing this invalid HTML. Thanks for filing this bug. I've fixed the issue that was preventing the adoption agency from keeping the original attributes in the new node. It will be available in 1.7.3, or you can build from head now.

这篇关于JSoup使用未关闭的标记解析无效的HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆