I have used Jsoup library to fetch the metadata from url.
Document doc = Jsoup.connect("http://www.google.com").get();
String keywords = doc.select("meta[name=keywords]").first().attr("content");
System.out.println("Meta keyword : " + keywords);
String description = doc.select("meta[name=description]").get(0).attr("content");
Elements images = doc.select("img[src~=(?i)\\.(png|jpe?g|gif)]");
String src = images.get(0).attr("src");
System.out.println("Meta description : " + description);
System.out.println("Meta image URl : " + src);
But I want to do it in client side using javascript
You can't do it client only because of the
cross-origin
issue. You need a server side script to get the content of the page.OR You can usehttps://policies.yahoo.com/us/en/yahoo/terms/product-atos/yql/index.htmYQL
. In this way, theYQL
will used as proxy.Or you can use https://cors-anywhere.herokuapp.com. In this way, cors-anywhere will used as proxy:
For example: