Search code examples
javaurlgoogle-apicode-snippetsbing-api

How to get snippet for an URL?


I have an URL, how can I get a description for this website (like snippets returned by Google) in Java. Is this possible with the Google API or Bing API?

HttpClient gives metadata, but we can't get the description of the website.


Solution

  • Usually that information is stored in a special meta tag in the <head>.

    <meta name="description" content="...Here goes the description your after...">
    

    So what you want to do is to parse the content of your URL looking for that meta data tag. (So no need to use the API.)

    And an example of how to parse and download the page can be found here Parse Web Site HTML with JAVA.

    But if you prefer to use the Bing API it will return the description as well in the xml or json payload, according to http://www.bing.com/developers/s/apibasics.html.

    Or with the Google API by using the custom search API and setting the c2coff property to 0, for more information of the API https://developers.google.com/custom-search/docs/xml_results.