0
votes

I want to extract from this HTML code the word Mustafa with Jsoup.

<h1 id="firstHeading" class="firstHeading">Mustafa</h1>
        <!-- /firstHeading -->

How can I do this?

1

1 Answers

2
votes

With Jsoup you can use CSS selectors to select elements. An element with id="firstHeading" is selectable with CSS selector #firstHeading.

Thus, this should do:

Document document = Jsoup.parse(html);
String firstHeading = document.select("#firstHeading").text();
System.out.println(firstHeading); // Mustafa