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
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)