Results 1 to 1 of 1
  1. #1
    Join Date
    Sep 2012
    Rep Power

    Default HtmlUnit - Iterating through DomNodes looking for specific node

    Hello all!

    I'm using HtmlUnit to get some values from a website. I'm creating an HtmlPage called page, getting page.getDescendants() in an Iterable<DomNode> named pageDesc. Then I iterate through pageDesc and use the if statement to look for the specific node <tr class="away">. The if statement below looks like it should work, but does not. I have an alternative way in comments that DOES work, but I would prefer to access the node using the way not in comments.
    Let me know if you need more info or you have an idea to try. Thanks!

    Java Code:
    public class Main{ 
             * @throws IOException 
             * @throws MalformedURLException 
             * @throws FailingHttpStatusCodeException 
            public static void main(String[] args) throws FailingHttpStatusCodeException, MalformedURLException, IOException { 
                    final WebClient webClient = new WebClient(); 
                    final HtmlPage page = webClient.getPage(""); 
                    Iterable<DomNode> pageDesc= page.getDescendants(); 
                    Iterator<DomNode> iterator = pageDesc.iterator(); 
                    while (iterator.hasNext()) { 
                            DomNode object =; 
                            if (object.getAttributes().getNamedItem("class").getNodeValue().toString().equals("away")) { 
    //	                if (object.toString().equals("HtmlTableRow[<tr class=\"away\">]")) { 
    //	                        if (object.getAttributes().getNamedItem("class").getNodeValue().toString().equals("away")) { 
    //	                                System.out.println(object.getAttributes().getNamedItem("class").getNodeValue()); 
    //	                        } 
    //	                } 
    Last edited by fiveironfrnzy80; 09-18-2012 at 10:08 PM. Reason: EditBB Code

Similar Threads

  1. Replies: 3
    Last Post: 06-26-2011, 11:00 AM
  2. using of htmlunit library
    By ahmad_javadi in forum Advanced Java
    Replies: 2
    Last Post: 07-26-2010, 11:43 AM
  3. use of pressAccessKey in htmlunit
    By ahmad_javadi in forum New To Java
    Replies: 1
    Last Post: 07-21-2010, 01:22 PM
  4. Specific syntax? java.util.regex.Pattern$Node
    By lmhelp2 in forum New To Java
    Replies: 1
    Last Post: 04-09-2010, 11:32 AM
  5. How to get value of specific child node
    By sito42 in forum New To Java
    Replies: 1
    Last Post: 07-13-2009, 12:00 PM

Tags for this Thread

Posting Permissions

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