how to get google custom search result in json array

user5245988 picture user5245988 · Jul 21, 2016 · Viewed 7.8k times · Source

I want to get google search results as json arrays in google latest custom search.

How to implement the code.

For Example :

 {
    "responseData": {` `
        "results": [
            {
      ` `          "GsearchResultClass ": "GwebSearch",
                "unescapedUrl": "http:/ / en.wikipedia.org/wiki/Paris_Hilton",
                "url"   : "http    ://    en.wikipedi a.org/wiki/Paris_Hilton",
                "visibleUrl  "  : "en.wikipedia .org",
                "cacheUrl    "    : "http://www.google.com/search?q=cache:TwrPfhd22hYJ:en.wikipedia.org",
                "title": "<   b>Paris Hilton</b   > - Wikipedia, the free encyclopedia",
                "titleNoFormatting": "Paris Hilton - Wikipedia, the free encyclopedia",
                "content": "[1] In 2006, she released her debut album..."
            },
            {
                "GsearchResultClass": "GwebSearch",
                "unescapedUrl": "http://`   `www.imdb.com/name/nm0385296/",
                "url": "http://`    `www.imdb.com/name/nm0385296/",
                "visibleUrl":     "www.imdb.com",
                "cacheUrl":      "http://www.google.com/search?q=cache:1i34KkqnsooJ:www.imdb.com",
                "title": "<b>    Paris Hilton</b>",
                "titleNoFormatting": "Paris Hilton",
                "content": "    Self: Zoolander. Socialite <b>Paris Hilton</b>..."
            }
        ]

Answer

vanloc picture vanloc · Jul 21, 2016

If you want a custom search result. Please read Custom Search Engine (free) of Google at:

Create custom search engine

And go to link to create your custom search:

https://cse.google.com/cse/

Or

You should go to:

Google search API

Click to link: Try this API in APIs Explorer

Insert your parameter:

  • "https://www.googleapis.com/customsearch/v1?"
    • "q=" + keyword (example: "Paris+Hilton")
    • "&cx=" + cx code of your CSE
    • "&key=" + your authorised API key [In link API project, click: A project is needed to enable APIs + Create project, then go to 'APIs & auth' and activate in 'Custom Search API']
    • "num=" + Number of search results to return (integer)

Press Execute to show a result with format JSON.