[英]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.