import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class Example {
public static void main(String[] args) {
Document document = Jsoup.parse(html);
Elements buttons = document.select("button");
for (Element button : buttons) {
System.out.println(button.attr("id"));
}
}
}
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class Example {
public static void main(String[] args) {
Document document = Jsoup.parse(html);
Element button = document.selectFirst("button");
String scriptCode = "$(document).ready(function(){" +
" $('#btn').click(function(){" +
" $('#btn').fadeOut(500).fadeIn(500);" +
" });" +
"});";
button.appendElement("script").append(scriptCode);
System.out.println(document.html());
}
}
html
<script src="js/jquery.js"></script>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.14.1</version>
</dependency>