Skip to content

Instantly share code, notes, and snippets.

@chowaikong
Created July 28, 2016 03:04
Show Gist options
  • Save chowaikong/a45d1009aa0063f13e5f888b01571b2b to your computer and use it in GitHub Desktop.
Save chowaikong/a45d1009aa0063f13e5f888b01571b2b to your computer and use it in GitHub Desktop.
Jsoup Get Metadata From HTML
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
public class JsoupGetMetaData {
public static void main(String args[]){
Document document;
String html = "";
try {
document = Jsoup.connect(html).get();
// both method below are working
String xx =
document.select("meta[name=xx]").get(0).attr("content"); // xx: your desire meta property
String xxx =
document.select("meta[name=xxx]").first().attr("content"); //xxx: your desire meta property
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment