import org.htmlparser.Parser; import org.htmlparser.util.NodeIterator; import org.htmlparser.util.ParserException; public class TagStripper{ public static void main(String[] args){ final StringBuilder text = new StringBuilder(); try { final Parser parser = new Parser ("http://www.javafr.com"); NodeIterator i = parser.elements(); while (i.hasMoreNodes()) text.append(i.nextNode().toPlainTextString()); System.out.println(text); } catch(ParserException e){ e.printStackTrace(); } } }
Salut,Avec un StringBuilder c'est beaucoup mieux...L'inconvénient de ta méthode c'est qu'à chaque itération il instancie un nouvel Objet String.ex:public static String HtmlToText(final String urlStr)throws ParserException { final StringBuilder text = new StringBuilder(); final Parser parser = new Parser(urlStr); for (final NodeIterator i = parser.elements(); i.hasMoreNodes();) text.append(i.nextNode().toPlainTextString()); return text.toString();};-)
ca serai rapide avec ca :String URL = "http://www.javafr.com";StringExtractor se = new StringExtractor (URL);String contents = se.extractStrings(true);System.out.println(contents);good luck :)
Se souvenir du profil
Mot de passe oublié ? / Activation de compteCréer un compte