Here you can find the source of getTitle(String htmlContent)
Parameter | Description |
---|---|
htmlContent | the HTML content that may contain a title |
public static String getTitle(String htmlContent)
//package com.java2s; //License from project: Apache License import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; public class Main { /**/*from ww w.j a v a 2s.com*/ * Get the title of the HTML. If no <code>title</code> tag exists, then the * title is null. * * @param htmlContent * the HTML content that may contain a title * @return the title of the HTML or null if none */ public static String getTitle(String htmlContent) { Document doc = Jsoup.parse(htmlContent); Elements titleNode = doc.select("head > title"); return titleNode.isEmpty() ? null : doc.title(); } }