Is there a Google API to capture the featured search information?

Asked

Viewed 1,393 times

3

Is there an API or something similar in which I can capture the featured information of a google search? For example, when I search "Bill Gates" appears on the right frame some information about it:

inserir a descrição da imagem aqui

1 answer

5


This painting is called Knowledge Graph and you can find the documentation here.

For example, when making this request (you will need to enter your API key):

https://kgsearch.googleapis.com/v1/entities:search? query=Bill+gates&key=API_KEY&limit=1&indent=True&languages=en

You will receive:

...
"itemListElement": [{
    "@type": "EntitySearchResult",
    "result": {
        "@id": "kg:/m/017nt",
        "name": "Bill Gates",
        "@type": [
            "Person",
            "Thing"
        ],
        "description": "Magnata",
        "image": {
            "contentUrl": "http://t0.gstatic.com/images?q=tbn:ANd9GcRXjfjE0L0XHKNqiGayo9stzrfNMkJs2wDxs36K1DStW1WqLi4p",
            "url": "https://en.wikipedia.org/wiki/Bill_Gates",
            "license": "http://creativecommons.org/licenses/by/2.0"
        },
        "detailedDescription": {
            "articleBody": "William Henry Gates III mais conhecido como Bill Gates, é um magnata, filantropo e autor norte-americano, que ficou conhecido por fundar junto com Paul Allen a Microsoft, a maior e mais conhecida empresa de software do mundo em termos de valor de mercado.\n",
            "url": "http://pt.wikipedia.org/wiki/Bill_Gates",
            "license": "https://en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License"
        },
        "url": "http://www.gatesnotes.com/"
    },
    "resultScore": 675.914368
}]
...

Google uses some information from Wikipedia - as the link just below the description of Bill Gates suggests. Wikipedia uses Mediawiki software, which has a API for queries. It may be interesting also to consult the data there.

For example, making the following request:

https://pt.wikipedia.org/w/api.php?action=parse&page=Bill_Gates&section=0&prop=wikitext

You’ll get:

{{Mais notas|data=outubro de 2014}}
{{Info/Biografia
|nome                =Bill Gates
|nome_completo       =William Henry Gates III
|conhecido_por       =ser fundador da [[Microsoft]]
|imagem              =Dts news bill gates wikipedia.JPG
|nascimento_local    =[[Seattle]], [[Condado de King (Washington)|King]], [[Washington]],<br /> {{USA}}
|residência          =[[Medina (Washington)|Medina]], King, Washington, <br />{{USAb}} Estados Unidos
|nacionalidade       =[[Estadunidenses|Norte-americano]]
|fortuna             ={{Increase}} [[Dólar dos Estados Unidos|US$]] 78.3 [[Bilhão|bilhões]] <small>(Agosto 2016)<ref name="net worth">{{cite web|title=#1 Bill Gates|url=http://www.forbes.com/profile/bill-gates/?list=billionaires|publisher=Forbes|accessdate=January 2, 2016}}</ref>
|legenda             =Bill Gates em [[Berlim]] (janeiro de 2013)
|data_nascimento     ={{nowrap|{{dni|lang=br|28|10|1955}}}}

etc...

From there, you have some options to extract the data, from using regex in this wikitext infobox or modifying the API request to return the already compiled HTML (prop=text), so you can use some HTML parser in php.

In addition to Wikipedia, Google also uses other sources. In the case of Bill Gates, they included his fortune from Forbes data. This magazine also has an API, and so on.

  • Man, thank you so much, I’ll test!

  • Just a quick question, to create this API need to pay? I went through the steps quickly and saw appeared "30 days" and something related to financial monitoring.

  • And I also thought that my language would be automatically picked up because of the API, but it was still in English.

  • 1

    You have to put the language in the URL according to the Reference of Knowledge Graph, edited the answer to correct the missing parameter. It has a limit of free queries so I know, take a look there right.

  • So you get paid :/, but thank you very much, man!

  • Amigo, goes to Cotas on your Google Cloud Platform (https://console.cloud.google.com/apis/apis/kgsearch.googleapis.com/quotas). There it shows the free limit of 100 thousand daily requests. It is only necessary to pay to increase this limit.

  • 1

    ah yes, I got it, thanks, I’ll give a better read on the documentation and etc.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.