try {
if (doc.isHTML() && (depth > 0)) {
// solving encoding problem
// HtmlDocument htmlDoc = new HtmlDocument(u, doc.getContent());
HtmlDocument htmlDoc = null;
HttpHeader contentTypeHeader = doc.getHeader("Content-type");
if (contentTypeHeader != null) {
String contentType = contentTypeHeader.getValue();
int index = contentType.toLowerCase().indexOf("charset=");
if (index > 0) {
htmlDoc = new HtmlDocument(u, doc.getContent(), contentType.substring(index+8));
} else {
htmlDoc = new HtmlDocument(u, doc.getContent());