Another solution is to first extract the meta tags for sharing social networks, if they are present, you are lucky, otherwise you can try other solutions.
<meta property="og:image" content="http://www.example.com/image.jpg"/> <meta name="twitter:image" content="http://www.example.com/image.jpg"> <meta itemprop="image" content="http://www.example.com/image.jpg">
If you use JSOUP, the code will be like this:
String imageUrlOpenGraph = document.select("meta[property=og:image]").stream() .findFirst() .map(doc -> doc.attr("content").trim()) .orElse(null); String imageUrlTwitter = document.select("meta[name=twitter:image]").stream() .findFirst() .map(doc -> doc.attr("content").trim()) .orElse(null); String imageUrlGooglePlus = document.select("meta[itemprop=image]").stream() .findFirst() .map(doc -> doc.attr("content").trim()) .orElse(null);
mmx73
source share