/*****************************************************************/ /* Copyright 2013 Code Strategies */ /* This code may be freely used and distributed in any project. */ /* However, please do not remove this credit if you publish this */ /* code in paper or electronic form, such as on a web site. */ /*****************************************************************/ package test; import org.htmlparser.Parser; import org.htmlparser.beans.StringBean; import org.htmlparser.util.ParserException; public class ConvertUrlContentToString2 { public static void main(String[] args) { try { Parser parser = new Parser("http://www.google.com"); StringBean stringBean = new StringBean(); parser.visitAllNodesWith(stringBean); String content = stringBean.getStrings(); System.out.println(content); System.out.println("================================================"); System.out.println("================================================"); stringBean.setLinks(true); parser.reset(); // start the parsing from the beginning again parser.visitAllNodesWith(stringBean); String contentWithLinks = stringBean.getStrings(); System.out.println(contentWithLinks); } catch (ParserException e) { e.printStackTrace(); } } }