Java HTML Parse Jsoup getTitle(String htmlContent)

Here you can find the source of getTitle(String htmlContent)

Description

Get the title of the HTML.

License

Apache License

Parameter

Parameter Description
htmlContent the HTML content that may contain a title

Return

the title of the HTML or null if none

Declaration

public static String getTitle(String htmlContent) 

Method Source Code

//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();
    }
}

Related

  1. getImageCredit(String html)
  2. getJSFileLinks(String html)
  3. getMetaValue(String html, String metaKey)
  4. getPlainText(String htmlText)
  5. getPlainTextFromHtml(String html)
  6. htmlArray2textArray(List htmlArray)
  7. isHTMLEmpty(String textToCheck)
  8. parse(final String html)
  9. parse(InputStream input, String documentIRI, String encoding)