Results 1 to 1 of 1
Thread: htmlparser inconsistent behavior
- 07-21-2009, 11:07 PM #1
Member
- Join Date
- Jan 2008
- Posts
- 3
- Rep Power
- 0
htmlparser inconsistent behavior
I have a method that takes a string of HTML from a page and then parses the nodes, looking for particular elements. I have used similar code successfully for other pages. If I run the code directly, the method occasionally returns null nodes partway through the page. If I run in debug mode, the method works correctly all the way through the page. There is no pattern to where the null node appears, and the page text is the same each time. I have put in debug statements to make sure the method is never called if the page is empty. No ParserException is triggered.
the code is basically this:
When it fails, the printout of namelist is always empty as well as the node.Java Code:import org.htmlparser.Parser; import org.htmlparser.util.NodeList; import org.htmlparser.nodes.*; import org.htmlparser.util.ParserException; import org.htmlparser.lexer.*; import org.htmlparser.filters.*; (removing standard class stuff, it is in my actual code which does compile and run) Lexer lexer=new Lexer(pageText); Parser parser=new Parser(lexer); HasAttributeFilter nameFilter=new HasAttributeFilter("class","name"); NodeList namelist=parser.parse(nameFilter); AbstractNode nameNode=(AbstractNode)namelist.elementAt(0); if(nameNode==null){ System.out.println("name node is null: "+namelist.toHtml()); }
I'm guessing there is some kind of race condition going on. I'm hoping someone on the forum can give me some additional debugging tips on how to nail this issue.
Similar Threads
-
Inconsistent ObjectInput/OutputStreams through Sockets
By Singing Boyo in forum Advanced JavaReplies: 1Last Post: 06-22-2009, 12:43 AM -
Question related to htmlParser
By java_org_bsb in forum New To JavaReplies: 1Last Post: 02-01-2009, 02:42 AM -
strange refreshing behavior
By diggitydoggz in forum New To JavaReplies: 4Last Post: 12-27-2008, 04:51 PM -
Inconsistent layout w/dynamic resize of components
By donb2000 in forum AWT / SwingReplies: 3Last Post: 07-26-2008, 02:40 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks