Re: [Htmlparser-user] Creating and using an HtmlPage object
Brought to you by:
derrickoswald
From: Brad <mai...@ya...> - 2005-02-11 03:09:58
|
On the money! Thanks Derrick. Maybe this dis-use of the parser object in the constructor could be made clear in the docs? Thanks again Brad NZ On Thu, 10 Feb 2005 01:05, Derrick Oswald wrote: > Brad, > > Even though the HtmlPage constructor takes a parser object it doesn't > use it. In fact it can be null. > This is probably a holdover from some previous use it had that was never > cleaned up. > Like all visitors, you need to apply it to the parser with: > parser.visitAllNodesWith (visitor); > > Derrick > > Brad wrote: > >Hi there > > > >I'm a first-time poster here and hoping for some great help. > > > >I have successfully implemented Parser(url) at various URLs, but wanted to > > use the HtmlPage object to be able to get tables and page title, etc, > > automatically. The following code runs with no errors, but gives no title > > and a zero table count. Any ideas? > > > >Thanks heaps > >Brad > >NZ > > > > > > > >public class TableFinder { > > > > public static org.htmlparser.tags.TableTag[] find(String url) { > > org.htmlparser.visitors.HtmlPage page; > > org.htmlparser.tags.TableTag[] tables = null; > > > > System.out.print("Resolving url..."); > > try { > > page = new org.htmlparser.visitors.HtmlPage( > >new org.htmlparser.Parser(url) > > ); > > System.out.println("done"); > > System.out.println("title: " + page.getTitle()); > > > > //*** get tables > > tables = page.getTables(); > > if (tables.length == 0) { > > System.err.println("No tables at this url"); > > return null; > > } > > > > } catch (org.htmlparser.util.ParserException e) { > > System.err.println("PARSE: Error parsing url"); > > } > > return tables; > > } > > > >} > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from real users. > Discover which products truly live up to the hype. Start reading now. > http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click > _______________________________________________ > Htmlparser-user mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/htmlparser-user |