Extract data from html code with Jsoup
I want to extract f开发者_StackOverflowrom this HTML code the word Mustafa
with Jsoup.
<h1 id="firstHeading" class="firstHeading">Mustafa</h1>
<!-- /firstHeading -->
How can I do this?
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
精彩评论