如何使用Java解码HTML代码? [英] how to decode html codes using Java?

查看:872
本文介绍了如何使用Java解码HTML代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:


我需要从 title ) > html 文件。

我可以在Java中使用正则表达式来提取我需要的字段,但是我必须 decode 获取字段。



示例



字段解压:

 分页Lucene&#39的搜索结果(在**&#39 **和** s **之间有**; **)

字段解码后:

 分页Lucene的搜索结果

java中是否有任何类允许我转换这些html代码?

解决方案

使用 Apache Commons Lang

  import org.apache.commons.lang.StringEscapeUtils; 
// ...
字符串afterDecoding = StringEscapeUtils.unescapeHtml(beforeDecoding);


Possible Duplicate:
Java: How to decode HTML character entities in Java like HttpUtility.HtmlDecode?

I need to extract paragraphs (like title in StackOverflow) from an html file.

I can use regular expressions in Java to extract the fields I need but I have to decode the fields obtained.

EXAMPLE

field extracted:

Paging Lucene&#39s search results (with **;** among **&#39** and **s**)

field after decoding:

Paging Lucene's search results

Is there any class in java that will allow me to convert these html codes?

解决方案

Use methods provided by Apache Commons Lang

import org.apache.commons.lang.StringEscapeUtils;
// ...
String afterDecoding = StringEscapeUtils.unescapeHtml(beforeDecoding);

这篇关于如何使用Java解码HTML代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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