【问题标题】:Extract data from html code with Jsoup使用 Jsoup 从 html 代码中提取数据
【发布时间】:2011-07-14 01:37:12
【问题描述】:

我想用 Jsoup 从这个 HTML 代码中提取单词Mustafa

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

我该怎么做?

【问题讨论】:

标签: java html-parsing jsoup


【解决方案1】:

使用Jsoup,您可以使用CSS selectors 选择元素。带有id="firstHeading" 的元素可以通过CSS 选择器#firstHeading 进行选择。

因此,应该这样做:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-29
    • 1970-01-01
    • 1970-01-01
    • 2019-09-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多