开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜