How to add a new html tag with Jsoup?
I'm having some trouble adding a new tag t开发者_Go百科o my Document. For example I have:
Document doc = Jsoup.parse(htmlString);
Element table = doc.select("table").first();
Now If I want to add a <LINK>
tag with attributes (href,type,rel) to my table element, and then return the total as a string, How would I do this?
Use something like this:
Jsoup.parse(new URL(""), 0).getElementById("test").appendElement("h1").attr("id", "header").text("Welcome");
And all ".append*" methods.
It's been quite some time but I also searched through for it a while so I will share my answer. This is for 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");
精彩评论