本文整理汇总了Java中org.htmlparser.beans.StringBean类的典型用法代码示例。如果您正苦于以下问题:Java StringBean类的具体用法?Java StringBean怎么用?Java StringBean使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StringBean类属于org.htmlparser.beans包,在下文中一共展示了StringBean类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getPlainText
import org.htmlparser.beans.StringBean; //导入依赖的package包/类
public static String getPlainText(String htmlStr) {
Parser parser = new Parser();
String plainText = "";
try {
parser.setInputHTML(htmlStr);
StringBean stringBean = new StringBean();
// 设置不需要得到页面所包含的链接信息
stringBean.setLinks(false);
// 设置将不间断空格由正规空格所替代
stringBean.setReplaceNonBreakingSpaces(true);
// 设置将一序列空格由单一空格替代
stringBean.setCollapse(true);
parser.visitAllNodesWith(stringBean);
plainText = stringBean.getStrings();
} catch (ParserException e) {
e.printStackTrace();
}
return plainText;
}
开发者ID:sercxtyf,项目名称:onboard,代码行数:24,代码来源:HtmlTextParser.java
示例2: html2text
import org.htmlparser.beans.StringBean; //导入依赖的package包/类
/**
* Converts an HTML document into plain text.
*
* @param html HTML document
* @return plain text or <code>null</code> if the conversion failed
*/
public static synchronized String html2text(String html) {
// convert HTML document
StringBean sb = new StringBean();
sb.setLinks(false); // no links
sb.setReplaceNonBreakingSpaces (true); // replace non-breaking spaces
sb.setCollapse(true); // replace sequences of whitespaces
Parser parser = new Parser();
try {
parser.setInputHTML(html);
parser.visitAllNodesWith(sb);
} catch (ParserException e) {
return null;
}
String docText = sb.getStrings();
if (docText == null) docText = ""; // no content
return docText;
}
开发者ID:claritylab,项目名称:lucida,代码行数:26,代码来源:HTMLConverter.java
示例3: file2text
import org.htmlparser.beans.StringBean; //导入依赖的package包/类
/**
* Reads an HTML document from a file and converts it into plain text.
*
* @param filename name of file containing HTML documents
* @return plain text or <code>null</code> if the reading or conversion failed
*/
public static synchronized String file2text(String filename) {
// read from file and convert HTML document
StringBean sb = new StringBean();
sb.setLinks(false); // no links
sb.setReplaceNonBreakingSpaces (true); // replace non-breaking spaces
sb.setCollapse(true); // replace sequences of whitespaces
Parser parser = new Parser();
try {
parser.setResource(filename);
parser.visitAllNodesWith(sb);
} catch (ParserException e) {
return null;
}
String docText = sb.getStrings();
return docText;
}
开发者ID:claritylab,项目名称:lucida,代码行数:24,代码来源:HTMLConverter.java
示例4: url2text
import org.htmlparser.beans.StringBean; //导入依赖的package包/类
/**
* Fetches an HTML document from a URL and converts it into plain text.
*
* @param url URL of HTML document
* @return plain text or <code>null</code> if the fetching or conversion failed
*/
public static synchronized String url2text(String url) throws SocketTimeoutException {
// connect to URL
URLConnection conn = null;
try {
conn = (new URL(url)).openConnection();
if (!(conn instanceof HttpURLConnection)) return null; // only allow HTTP connections
} catch (IOException e) {
return null;
}
conn.setRequestProperty("User-agent","Mozilla/4.0"); // pretend to be a browser
conn.setConnectTimeout(TIMEOUT);
conn.setReadTimeout(TIMEOUT);
// fetch URL and convert HTML document
StringBean sb = new StringBean();
sb.setLinks(false); // no links
sb.setReplaceNonBreakingSpaces(true); // replace non-breaking spaces
sb.setCollapse(true); // replace sequences of whitespaces
sb.setConnection(conn);
String docText = sb.getStrings();
return docText;
}
开发者ID:claritylab,项目名称:lucida,代码行数:30,代码来源:HTMLConverter.java
注:本文中的org.htmlparser.beans.StringBean类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论