Jsoup示例(打印URL的元数据)

在此示例中, 我们将打印meta关键字和URL的描述。为此, 你需要调用Document类的select(), first(), get()和attr()方法。

import java.io.IOException; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; public class JsoupPrintMetadata { public static void main( String[] args ) throws IOException{ Document doc = Jsoup.connect("http://www.srcmini.com").get(); String keywords = doc.select("meta[name=keywords]").first().attr("content"); System.out.println("Meta keyword : " + keywords); String description = doc.select("meta[name=description]").get(0).attr("content"); System.out.println("Meta description : " + description); } }

【Jsoup示例(打印URL的元数据)】输出:
Meta keyword : jsoup, tutorial, beginners, professionals, introduction, example, java, html, parser Meta description : Jsoup tutorial for beginners and professionals provides html parsing facility in java with examples of printing title, links, images, form elements from url.

    推荐阅读