Results 1 to 2 of 2
Thread: Question related to htmlParser
- 01-31-2009, 04:59 PM #1
Member
- Join Date
- Jan 2009
- Posts
- 1
- Rep Power
- 0
Question related to htmlParser
Hello, i have to use an htmlParser and i have to visit the nodes/children in the DOM tree which attribute is href.
It's just that i need to parse the html and gather all the links included in " " marks
For example : <a href=" url ">
So i have the following code :
Hm...it's just that i have to visit every children/node and find the nodes/elements with attribute hrefJava Code:import org.htmlparser.Parser; import org.htmlparser.Tag; import org.htmlparser.Text; import org.htmlparser.util.ParserException; import org.htmlparser.visitors.NodeVisitor; public class MyVisitor extends NodeVisitor { public MyVisitor () { } /**/ @Override public void visitTag (Tag tag) { System.out.println ("\n" + tag.getTagName () + tag.getStartPosition ()); } public static void main (String[] args) throws ParserException { Parser parser = new Parser (" whatever, link"); NodeVisitor visitor = (NodeVisitor) new MyVisitor (); parser.visitAllNodesWith(visitor); visitor.visitTag(/* Here i cannot place a string but only a Tag */); // I would like to visit every Tag in the page and i'm stuck, // I don't know how to do that! } }
May you please help me?
Thanks in advance! :rolleyes:
- 02-01-2009, 02:42 AM #2
I've been doing something like this recently. I don't use a html parser, but maybe you could adapt my code somewhat:
I used a buffered reader and read the lines in one at a time feeding it to this code:
It basically extracts text between two values and creates a substring, storing it into a stringJava Code:String slice = "< a href="; int beg = inputLine.indexOf(slice) + slice.length(); int end = inputLine.indexOf(">"); String sliced = inputLine.substring(beg, end)Last edited by VeasMKII; 02-01-2009 at 02:45 AM.
Similar Threads
-
Related to JTrees
By swathi in forum AWT / SwingReplies: 1Last Post: 11-21-2008, 06:50 AM -
Jboss related.
By CharanZ in forum IntroductionsReplies: 0Last Post: 10-27-2008, 10:09 AM -
Sql Server Related
By Ganeshag777 in forum JDBCReplies: 1Last Post: 08-28-2008, 05:54 PM -
JNDI Related
By Ganeshag777 in forum Advanced JavaReplies: 0Last Post: 08-13-2008, 01:18 PM -
JDBC Related
By Ganeshag777 in forum JDBCReplies: 2Last Post: 08-13-2008, 12:42 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks