Imagine that i need to get the link within this part of my html:
<a href="http://www.cs.ucla.edu">UCLA Computer Science Department</a>
I need to get the physical link of http://www.cs.ucla.edu but according to what I have (using filters):
Parser parser = new Parser ("http://www.cs.ucla.edu/~todd/"); NodeList list = new NodeList (); NodeFilter filter = new AndFilter ( new TagNameFilter ("a"), new HasAttributeFilter("href") ); for (NodeIterator e = parser.elements (); e.hasMoreNodes (); ){ e.nextNode ().collectInto(list, filter);
this only returns the text between the tags... rather than the link itself. Can someone help me out?
I found the answer my question. Here is what i did....
Parser parser = new Parser ("http://www.cs.ucla.edu/"); NodeList list = new NodeList (); NodeFilter filter = new AndFilter ( new TagNameFilter ("a"), new HasAttributeFilter("href") ); list = parser.extractAllNodesThatMatch(filter); for(Integer i = 0; i < list.size(); i ++){ String links = ((LinkTag)(list.elementAt (i))).extractLink (); StringBuffer link_buffer = new StringBuffer(); link_buffer.append(links); System.out.println (link_buffer); }
Hi samsina I am a new to HTMLParser. I get the HypertextLinkes with your reply/help. :)
best regards
wjs
Log in to post a comment.
Imagine that i need to get the link within this part of my html:
<a href="http://www.cs.ucla.edu">UCLA Computer Science Department</a>
I need to get the physical link of http://www.cs.ucla.edu but according to what I have (using filters):
Parser parser = new Parser ("http://www.cs.ucla.edu/~todd/");
NodeList list = new NodeList ();
NodeFilter filter =
new AndFilter (
new TagNameFilter ("a"),
new HasAttributeFilter("href")
);
for (NodeIterator e = parser.elements (); e.hasMoreNodes (); ){
e.nextNode ().collectInto(list, filter);
this only returns the text between the tags... rather than the link itself. Can someone help me out?
I found the answer my question.
Here is what i did....
Parser parser = new Parser ("http://www.cs.ucla.edu/");
NodeList list = new NodeList ();
NodeFilter filter =
new AndFilter (
new TagNameFilter ("a"),
new HasAttributeFilter("href")
);
list = parser.extractAllNodesThatMatch(filter);
for(Integer i = 0; i < list.size(); i ++){
String links = ((LinkTag)(list.elementAt (i))).extractLink ();
StringBuffer link_buffer = new StringBuffer();
link_buffer.append(links);
System.out.println (link_buffer);
}
Hi samsina
I am a new to HTMLParser. I get the HypertextLinkes with your reply/help. :)
best regards
wjs