
可以解决这个问题,但是返回的结果如果span元素还有parent元素的话就不正确了,当然前提是不知道要解析的html代码是什么样的,所以应该这样做:
public String parse(String text) {
String tmp = "<html><body>" + text + "</body></html";
NodeList list = ParsercreateParser(tmp, "GB2312")parse(new TagNameFilter("body"));
Node body = tmpelementAt(0);
bodyaccept(new NodeVisitor() {
public void visitTag(Tag tag) {
if (taggetClass() != Spanclss) return;
// replace attribute here,i ignore the code
}
});
return bodytoHtml();
}
以上就是关于如何用htmlparser修改html中标签的内容全部的内容,包括:如何用htmlparser修改html中标签的内容、、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)