The unix command line utility watch allows you to monitor the output of a command continuously. I found this port which works on my Mac with a minor modification to it's Makefile. Basically, since a Mac system may not have the /usr/local dir, the BINDIR in Makefile should point to somewhere else, say /usr/bin/watch
Tuesday, February 24, 2009
`watch` with the Mac
The unix command line utility watch allows you to monitor the output of a command continuously. I found this port which works on my Mac with a minor modification to it's Makefile. Basically, since a Mac system may not have the /usr/local dir, the BINDIR in Makefile should point to somewhere else, say /usr/bin/watch
Wednesday, February 04, 2009
java HTMLParser - handling EncodingChangeException
![](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));
}
Subscribe to:
Posts (Atom)