To Check Google Indexation for bulk urls via API



Are you looking to ensure that your website's URLs are being properly indexed by Google? 

Here's a quick guide on how to check the indexation status for multiple URLs at once!

In this article, we explore the process of using the Google Indexing API to submit URLs for indexing in bulk. By leveraging this powerful tool, you can efficiently monitor and manage the indexation status of your website's content.

Don't miss out on this valuable resource! Whether you're a website owner, developer, or SEO professional, mastering the art of Google indexation is crucial for maximizing your online visibility and driving organic traffic.



To check if a page is indexed in Google using the Google Search Console API, you can follow these general steps:

Set up Google Search Console: Make sure you have access to Google Search Console and have added the website whose pages you want to check.

1. Set up Google API credentials:

Go to the Google Cloud Console. https://console.cloud.google.com/welcome

Create a new project or select an existing one.

Enable the "Search Console API" for your project. https://console.cloud.google.com/marketplace/product/google/searchconsole.googleapis.com

Click on Manage Api

Create Service Account for your site, from manage service account tab

Make it as owner in role

Go to detail, copy email address

Make this email id as onwer in your site GSC account.

Go to Key tab

Add key > Create New Key > Json

Create credentials for a service account and download the JSON file containing the key and save it in desktop.

Install Google API Client Library: Install the Google API Client Library for your programming language of choice (e.g., Python, JavaScript).

2. Install Python latest version

Open command prompt

Type cd desktop enter


3. Install the Google API Python client library using the following command:

pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib

Query the Index Status: Once authenticated, you can use the Search Console API's urlTestingTools resource to check if pages are indexed. 

Specifically, you'll use the inspect method to check the index status of individual URLs.

Bulk Processing: To check multiple URLs in bulk, you'll need to loop through your list of URLs and make a request for each one to check its index status.

Here's a simplified Python example using the google-auth and google-auth-oauthlib libraries for authentication and the googleapiclient library for making requests to the Google Search Console API:

4. Copy below code in notepad, Replace 'path/to/credentials.json' with the path to your downloaded JSON key file, remove double inverted comma and change back slash with forward slash.
Insert list of urls in "urls_to_check = [" with the list of URLs you want to check in the code. Replace your website url : siteUrl= :


from google.oauth2 import service_account

from googleapiclient.discovery import build

from googlesearch import search


# Set up authentication for Google Search Console API

SCOPES = ['https://www.googleapis.com/auth/webmasters']

SERVICE_ACCOUNT_FILE = 'C:/Users/10151977/Desktop/hvbari-1a188aca4fe2.json'

credentials = service_account.Credentials.from_service_account_file(

    SERVICE_ACCOUNT_FILE, scopes=SCOPES)


# Build the Search Console service

service = build('searchconsole', 'v1', credentials=credentials)


def check_index_status(url):

    try:

        request = {

            'startDate': '2000-01-01',

            'endDate': '2024-02-06',

            'dimensions': ['page'],

            'dimensionFilterGroups': [{

                'filters': [{

                    'dimension': 'page',

                    'operator': 'equals',

                    'expression': url

                }]

            }]

        }

        response = service.searchanalytics().query(siteUrl='https://hbari.blogspot.com', body=request).execute()

if 'rows' in response:

            return True

        else:

            return False

    except Exception as e:

        print(f"Error checking index status for URL {url} using API: {str(e)}")

        return None


def check_index_status_search(url):

    try:

        search_results = list(search(url, num=1, stop=1, pause=2))

        if search_results and url in search_results[0]:

            return True

        else:

            return False

    except Exception as e:

        print(f"Error checking index status for URL {url} using search: {str(e)}")

        return None


def check_index_status(url):

    indexed_api = check_index_status_api(service, url)  # Pass 'service' object as argument

    indexed_search = check_index_status_search(url)

    if indexed_api is not None and indexed_search is not None:

        return indexed_api or indexed_search

    else:

        return None


# List of URLs to check

urls_to_check = [

  'https://hbari.blogspot.com/2005/10/seo-point-of-view-mistakes-to-be.html',

  'https://hbari.blogspot.com/',

'https://hbari.blogspot.com/2023/07/',

'https://hbari.blogspot.com/2010/03/your-blood-group.html',

'https://hbari.blogspot.com/2023/02/Best-SEO-strategy-2023.html',

'https://hbari.blogspot.com/2010/03/accu-pressure-on-your-hand-and-leg.html',

'https://hbari.blogspot.com/2009/10/2-bit-defender-antivirus-2009.html',

'https://hbari.blogspot.com/2009/10/5-norton-internet-security-2009.html',

'https://hbari.blogspot.com/2009/10/9avast-professional-edition.html',

'https://hbari.blogspot.com/2009/10/avg-internet-security-2009.html',




    # Add more URLs here

]


# Check index status for each URL

for url in urls_to_check:

    index_status = check_index_status(url)

    if index_status is not None:

        print(f"URL: {url}, Indexed: {index_status}")

    else:

        print(f"URL: {url}, Unable to determine index status")


5. Run the Script: Save the above script with a .py extension (e.g., hvbari_indexation.py).

Open your terminal or command prompt, navigate to the directory where the file is saved, and run the script using Python: hvbari_indexation.py


0 comments:

Post a Comment

Most Viewed Posts from hbari.blogspot.com