private boolean getTextHelper(StringBuffer sb, Node node, boolean abortOnNestedAnchors, int anchorDepth) { if ("script".equalsIgnoreCase(node.getNodeName())) { return false; } if ("style".equalsIgnoreCase(node.getNodeName())) { return false; } if (abortOnNestedAnchors && "a".equalsIgnoreCase(node.getNodeName())) { anchorDepth++; if (anchorDepth > 1) return true; } if (node.getNodeType() == Node.COMMENT_NODE) { return false; }
if (node.getNodeType() == Node.TEXT_NODE) { //node是解析下来的网页源文件所包含的内容
//Node.TEXT_NODE:节点属于文本节点<body><div><a href><td>等标签 // cleanup and trim the value String text = node.getNodeValue(); //获取节点里面的文本内容,相当与去掉HTML标签
text = text.replaceAll("//s +", " "); text = text.replace("【", ""); text = text.replace("】", ""); text = text.replace("[", ""); text = text.replace("]", ""); text = text.replace("|", ""); text = text.replace("┊", ""); text = text.replace("?", ""); text = text.replace("?", ""); text = text.replace("?", ""); text = text.replace("|", ""); text = text.replace("、", ""); text = text.replace("-", ""); text = text.replace("~", ""); text = text.replace("!", ""); text = text.replace("@", ""); text = text.replace("#", ""); text = text.replace("$", ""); text = text.replace("^", ""); text = text.replace("*", ""); text = text.replace("(", ""); text = text.replace(")", ""); text = text.replace("%", ""); text = text.replace(">", ""); text = text.replace("?", ""); text = text.replace("%", "");