Results 1 to 1 of 1
- 09-18-2012, 09:15 PM #1
Member
- Join Date
- Sep 2012
- Posts
- 5
- Rep Power
- 0
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("http://mlb.mlb.com/mlb/scoreboard/index.jsp?c_id=det"); Iterable<DomNode> pageDesc= page.getDescendants(); Iterator<DomNode> iterator = pageDesc.iterator(); while (iterator.hasNext()) { DomNode object = iterator.next(); if (object.getAttributes().getNamedItem("class").getNodeValue().toString().equals("away")) { System.out.println(object.getAttributes().getNamedItem("class").getNodeValue()); } // 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()); // } // } } webClient.closeAllWindows(); } }Last edited by fiveironfrnzy80; 09-18-2012 at 10:08 PM. Reason: EditBB Code
Similar Threads
-
Is there a way to read a specific line in a txt file (without iterating through)?
By TheNadz in forum New To JavaReplies: 3Last Post: 06-26-2011, 11:00 AM -
using of htmlunit library
By ahmad_javadi in forum Advanced JavaReplies: 2Last Post: 07-26-2010, 11:43 AM -
use of pressAccessKey in htmlunit
By ahmad_javadi in forum New To JavaReplies: 1Last Post: 07-21-2010, 01:22 PM -
Specific syntax? java.util.regex.Pattern$Node
By lmhelp2 in forum New To JavaReplies: 1Last Post: 04-09-2010, 11:32 AM -
How to get value of specific child node
By sito42 in forum New To JavaReplies: 1Last Post: 07-13-2009, 12:00 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks