Results 1 to 7 of 7
Thread: Parsing HTML
- 07-17-2008, 07:31 PM #1
Member
- Join Date
- Jul 2008
- Posts
- 4
- Rep Power
- 0
Parsing HTML
I am trying to parse the HTML, and for a HTML code like this
<span class="authorName">Paul Abbott </span>
I want to retrieve the value "Paul Abbott"
Right now, I am using a parser, to generate the HTML tree and by using the this code..
************************************************** *******************
Tidy tidy = new Tidy();
tidy.setXHTML(xhtml);
d = tidy.parseDOM(in,out);
NodeList spanNode = d.getElementsByTagName("span");
int length = spanNode.getLength();
for(int i = 0;i<length;i++)
{
org.w3c.dom.Node span = spanNode.item(i);
String tempAltText = span.getAttributes().getNamedItem("class").getNode Value();
if(tempAltText.equals("authorName")){
System.out.println("the item is " + tempAltText);
}
else{
}
}
************************************************** ************
The tempAltText displays "authorName" but not "Paul Abott"
please give me some suggestions...how can i do that...
- 07-17-2008, 10:20 PM #2
Don't know about parsing HTML, but your if test give you what you want.
Its like asking if x == 1 and then being suprised that x is equal to 1. Perhaps you need to get some other item.
- 07-17-2008, 10:27 PM #3
Member
- Join Date
- Jul 2008
- Posts
- 4
- Rep Power
- 0
The thing is I want to dispaly "paul Abott" not "authorName".....how can i do that...
Is it clear now...or if you need more explanation...let me know..
- 07-18-2008, 07:53 PM #4
On forums, its generally a good idea to post the solution, so others with the same problem can benefit from the effort you put into finding a solution.
- 07-18-2008, 08:23 PM #5
Member
- Join Date
- Jul 2008
- Posts
- 4
- Rep Power
- 0
I am still looking for the solution..I haven't solved it yet...
- 07-19-2008, 04:43 PM #6
Member
- Join Date
- Jul 2008
- Posts
- 28
- Rep Power
- 0
Are you looking at the API? There are a handful of "get" methods and I'm pretty sure at least one of them works! ;)
Node (Java Platform SE 6)
- 07-20-2008, 06:51 PM #7
Member
- Join Date
- Jul 2008
- Posts
- 33
- Rep Power
- 0
I've seen a similiar question on the sun java forums and i've answered it but because he went postal i've removed my code and let him sort it out on his own..
:DMy community with sourcode and examples :D
Java remote image server/client working proof of concept: uitstekendeaccu.nl/tmp/
Similar Threads
-
html web page parsing/scraping
By orchid in forum Advanced JavaReplies: 3Last Post: 10-21-2010, 01:34 PM -
xml parsing
By gaurav65176 in forum XMLReplies: 5Last Post: 11-12-2008, 11:07 AM -
Parsing URL
By Java Tip in forum Java TipReplies: 0Last Post: 12-26-2007, 10:16 AM -
jeditorpane help parsing html
By asifsolkar in forum Advanced JavaReplies: 4Last Post: 12-14-2007, 05:23 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks