![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinzqvw0VX2XzS-cs3e-sfJEJq5FCuYpKLtuCee-qT3M8gVafXR6WFBwhkC5CTNL42SZY5GMb4IauG2RLTs9-8CK3MX3-I3C10wDgMVgLuf1q3aX_UKYU2sPI0Y0kK8rh3ln5VY6w/s400/htmlparserlogo.jpg)
If you are analyzing a web page containing characters with different encodings, the HTMLParser may throw an exception of type EncodingChangeException.
The correct way to handle this exception is to reset the parser and re-try parsing. On the second time, the HTMLParser is aware of multiple encodings and manages to parse the page without exceptions.
ex:
NodeList nodes = null;
try {
nodes = parser.extractAllNodesThatMatch(new NodeClassFilter(TitleTag.class));
} catch (EncodingChangeException ex) {
//accommodate new encoding, re-parse
parser.reset();
nodes = parser.extractAllNodesThatMatch(new NodeClassFilter(TitleTag.class));
}
No comments:
Post a Comment