How to get page meta (title, description, images) like facebook attach url using Regex in .java
How about this? Below statement parse all tags start with "og:". It's useful.
doc.select("meta[property^=og:]")
void parseOGTag(String response) {
// Parse og tags
Document doc = Jsoup.parse(response);
Elements ogTags = doc.select("meta[property^=og:]");
if (ogTags.size() <= 0) {
return;
}
// Set OGTags you want
String title;
String desc;
String image;
for (int i = 0; i < ogTags.size(); i++) {
Element tag = ogTags.get(i);
String text = tag.attr("property");
if ("og:image".equals(text)) {
image = tag.attr("content");
} else if ("og:description".equals(text)) {
desc = tag.attr("content");
} else if ("og:title".equals(text)) {
title = tag.attr("content");
}
}
}