Re: [Htmlparser-user] Need Help
Brought to you by:
derrickoswald
From: Miguel A. M. <mig...@gm...> - 2012-08-08 15:42:16
|
Hello AniketP, I had the same problem but whit the bold and italics tags (<b> and <i> respectively). Here is my solution for <i> tags: Create a class for the tag you are interested in, that extends CompositeTag: public class ItalicTag *extends CompositeTag*{ private static final String[] mIds = new String[] {*"I"*}; //Change this as appropriate public ItalicTag () { } public String[] getIds () { return (mIds); } public String[] getEnders () { return (mIds); } public String[] getEndTagEnders () { return (new String[0]); } } //In your main class: factory = new PrototypicalNodeFactory(); // create a factory factory.registerTag(new ItalicTag ()); //register your new tag try { Parser parser = new Parser (URL); parser.setNodeFactory(factory); NodeList list; NodeFilter tagfilter = new NodeClassFilter(ItalicTag.class); list = parser.extractAllNodesThatMatch(tagfilter); for (Node node : list.toNodeArray()) { String texto = *extractText*(node); // In this function we will extract the content between tags (<i> </i>) } } catch (ParserException ex) { //do something } //the extactText method : /** *Gets the text that is enclosed between labels. In order to do that *it studies the children components in the labels in a recursive way. * * @param studiedNode * @return Text between nested tags */ public String *extactText *(Node studiedNode ) { Node node; String text = ""; boolean exit= false; try { for (SimpleNodeIterator e = studiedNode .getChildren().elements(); e.hasMoreNodes() && !exit;) { node = e.nextNode(); if (node instanceof CompositeTag) { text = extactText (node); } else { if (node != null) { text = node.getText(); } exit= true; } } } catch (NullPointerException ex) { // do something } return text.trim(); } I hope this helps. On 8 August 2012 10:57, Aniket P <ani...@gm...> wrote: > Hello all, > Currently I am using the htmlparser in my work. I want to extract <script> > </script> part, and more specifically I want to extract different functions > in <script> </script>. After that I need to execute those functions. So can > anyone please help me how to use that?? > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Htmlparser-user mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/htmlparser-user > > |