ColdFusion에서 HtmlCleaner를 사용하고 있습니다. 아래의 코드에서 노드 트리를 가로 지르고 내용 노드를 찾습니다. 내가하고 싶은 것은 노드의 텍스트 내용을 수정할 수 있어야한다는 것입니다.HtmlCleaner ContentNodes 사용 및 텍스트 내용 수정
node.traverse(new TagNodeVisitor() {
public boolean visit(TagNode tagNode, HtmlNode htmlNode) {
if (htmlNode instanceof ContentNode) {
ContentNode content = ((ContentNode) htmlNode);
String textContent = content.getContent();
}
// tells visitor to continue traversing the DOM tree
return true;
}
});
내가 사용 예는 다음과 같습니다
// traverse whole DOM and update images to absolute URLs
node.traverse(new TagNodeVisitor() {
public boolean visit(TagNode tagNode, HtmlNode htmlNode) {
if (htmlNode instanceof TagNode) {
TagNode tag = (TagNode) htmlNode;
String tagName = tag.getName();
if ("img".equals(tagName)) {
String src = tag.getAttributeByName("src");
if (src != null) {
tag.setAttribute("src", Utils.fullUrl(siteUrl, src));
}
}
} else if (htmlNode instanceof CommentNode) {
CommentNode comment = ((CommentNode) htmlNode);
comment.getContent().append(" -- By HtmlCleaner");
}
// tells visitor to continue traversing the DOM tree
return true;
}
});
내가 jsoup의 알고 있지만, Htmlcleaner 사이트들이 주석 노드에 텍스트를 추가 할 경우 예를 준다 그들을 ranslate. comment.getContent(). append ("- By HtmlCleaner"); 하지만 그것을 시도하면 오류가 발생합니다. – jonesk
@ user3653457 : 귀하의 질문 게시판에 꼭 있어야하는 정보입니다. –
James는 모든 텍스트 노드를 가로 지르며 수정할 수있는 예제가 있습니다. 동적이어야하며 특정 태그를 찾고 있지 않습니다. – jonesk