Results 1 to 7 of 7

Thread: Parsing HTML

  1. #1
    jaadu25 is offline Member
    Join Date
    Jul 2008
    Posts
    4
    Rep Power
    0

    Default 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...

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,422
    Rep Power
    25

    Default

    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.

  3. #3
    jaadu25 is offline Member
    Join Date
    Jul 2008
    Posts
    4
    Rep Power
    0

    Default

    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..

  4. #4
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    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.

  5. #5
    jaadu25 is offline Member
    Join Date
    Jul 2008
    Posts
    4
    Rep Power
    0

    Default

    I am still looking for the solution..I haven't solved it yet...

  6. #6
    Jeremy is offline Member
    Join Date
    Jul 2008
    Posts
    28
    Rep Power
    0

    Default

    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)

  7. #7
    Join Date
    Jul 2008
    Posts
    33
    Rep Power
    0

    Default

    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

  1. html web page parsing/scraping
    By orchid in forum Advanced Java
    Replies: 3
    Last Post: 10-21-2010, 01:34 PM
  2. xml parsing
    By gaurav65176 in forum XML
    Replies: 5
    Last Post: 11-12-2008, 11:07 AM
  3. Parsing URL
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-26-2007, 10:16 AM
  4. jeditorpane help parsing html
    By asifsolkar in forum Advanced Java
    Replies: 4
    Last Post: 12-14-2007, 05:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •