Google is the most famous search engine. Google offers Google knowledge graph results for some keywords. Google gathers information from various sources to create a structured and comprehensive representation of facts about people, places, companies and things.

Google Knowledge Graph is one of the good quality sources to enhance your search results, providing more detailed and contextually relevant information directly on the search results page.

By scraping the Google Knowledge graph, you can give a quick answer, get all linking information, help your AI semantic understanding of language and user queries, leading to more accurate search results.

In my previous blog post, I showed you how to scrape Bing Knowledge Graph in minutes. It would be easy to scrape Google Knowledge Graph with SerpApi.

Setting up a SerpApi account

SerpApi offers a free plan for newly created accounts. Head to the sign-up page to register an account and complete your first search with our interactive playground. When you want to do more searches with us, please visit the pricing page.

Once you are familiar with all results, you can utilize SERP APIs using your API Key.

Scrape your first Google Knowledge graph results with SerpApi

Head to the Google Knowledge Graph Results from the documentation on SerpApi for details.

In this tutorial, we will scrape all listening sources of "Taylor Swift" using Google Knowledge Graph results. The data contains: "name", "link", "image". You can also scrape more information with SerpApi.

First, you need to install the SerpApi client library.

pip install google-search-results

Set up the SerpApi credentials and search.

import serpapi, os, json

params = {
    'api_key': 'YOUR_API_KEY',         # your serpapi api
    'engine': 'google',                # SerpApi search engine	
    'q': 'Taylor Swift'
}

To retrieve Google Knowledge Graph Results for a given search term, you can use the following code:


results = serpapi.Client().search(params).get_dict()['knowledge_graph']['listen']

You can store Google Knowledge Graph Results JSON data in databases or export them to a CSV file.

import csv

header = ['name', 'link', 'image']

with open('listen.csv', 'w', encoding='UTF8', newline='') as f:
    writer = csv.writer(f)

    writer.writerow(header)

    for item in results:
        print(item)
        writer.writerow([item.get('name'), item.get('link'), item.get('image')])

This example is using Python, but you can also use your all your favorite programming languages likes Ruby, NodeJS, Java, PHP....

If you have any questions, please feel free to contact me.