[英]How to add a new html tag with Jsoup?
我在向我的文档添加新标签时遇到了一些问题。 例如我有:
Document doc = Jsoup.parse(htmlString);
Element table = doc.select("table").first();
现在,如果我想将带有属性(href、type、rel)的<LINK>
标记添加到我的表元素,然后将总数作为字符串返回,我该怎么做?
使用这样的东西:
Jsoup.parse(new URL(""), 0).getElementById("test").appendElement("h1").attr("id", "header").text("Welcome");
以及所有“.append*”方法。
已经有一段时间了,但我也搜索了一段时间,所以我会分享我的答案。 这是 Jsoup 1.13.1
Document doc = Jsoup.parse(htmlString);
Element table = doc.select("table").first();
table.appendElement("link").attr("href","example.com/file.css").attr("rel","stylesheet").attr("type","text/css");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.