0

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 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.