Hi,
how do I parse a file on my pc
File file = new File(filepath);
Parser parser = new Parser (file.getAbsolutePath()); NodeIterator ni = parser.elements(); Node htmlNode = ni.nextNode();
I tried this but it threw and error
org.htmlparser.util.ParserException: D:\program\java\src\resources\wb1931_a.html (The system cannot find the file specified);
the file is in that directory
pls help
There is code in Parser.java to do this.
final String prefix = "file://localhost"; File file = new File (string); String resource = file.getCanonicalPath (); StringBuffer buffer = new StringBuffer (prefix.length () + resource.length ()); buffer.append (prefix); if (!resource.startsWith ("/")) buffer.append ("/"); buffer.append (resource); url = new URL (fixSpaces (buffer.toString ()));
then you can use url.toExternalForm().
I have tried this code, but I cannot get any content after parser.extractAllNodesThatMatch (filter); although I sucessfully complied the code
Try a less restrictive filter, or if the problem is trying to re-get nodes after calling extractAllNodesThatMatch() then use parser.reset().
Log in to post a comment.
Hi,
how do I parse a file on my pc
File file = new File(filepath);
Parser parser = new Parser (file.getAbsolutePath());
NodeIterator ni = parser.elements();
Node htmlNode = ni.nextNode();
I tried this
but it threw and error
org.htmlparser.util.ParserException: D:\program\java\src\resources\wb1931_a.html (The system cannot find the file specified);
the file is in that directory
pls help
There is code in Parser.java to do this.
final String prefix = "file://localhost";
File file = new File (string);
String resource = file.getCanonicalPath ();
StringBuffer buffer = new StringBuffer (prefix.length () + resource.length ());
buffer.append (prefix);
if (!resource.startsWith ("/"))
buffer.append ("/");
buffer.append (resource);
url = new URL (fixSpaces (buffer.toString ()));
then you can use url.toExternalForm().
I have tried this code, but I cannot get any content after parser.extractAllNodesThatMatch (filter);
although I sucessfully complied the code
Try a less restrictive filter, or if the problem is trying to re-get nodes after calling extractAllNodesThatMatch() then use parser.reset().