Introduction
Indexing your web pages fast on Google can be a game-changer for SEO. Instead of waiting days or weeks for Google to crawl your site, you can use Google’s Indexing API to notify Google about new or updated pages in real time. This guide will walk you through the process of using Python in Google Colab to index your URLs fast.
Prerequisites
Before we start, ensure you have the following:
- A Google Cloud Project with Indexing API enabled.
- A Service Account JSON Key for authentication.
- A Google Search Console-verified website.
- Access to Google Colab to run Python scripts.
Step 1: Enable Google Indexing API
-
- Go to Google Cloud Console
- Create or select a project.
- Navigate to APIs & Services > Library.
4. Search for Indexing API and enable it.
Step 2: Create a Service Account and Get JSON Key
- Go to APIs & Services > Credentials.
2. Click Create Credentials > Service Account.
3. Assign a name and create a service account.
4. Under Keys, click “Add Key” and choose JSON.
5. This will download the JSON file automatically.
Step 3: Add Service Account to Google Search Console
- Open Google Search Console.
- Select the property (website) you want to index.
- Click Settings > Users & permissions.
- Add the service account email from the JSON key as a user.
Step 4: Run Python Program in Google Colab
- Open Google Colab – https://colab.research.google.com/
- Create a new notebook.
3. Upload the downloaded JSON file.
4. Add the below code in the notebook.
from oauth2client.service_account import ServiceAccountCredentials import httplib2 import json SCOPES= [ "https://www.googleapis.com/auth/indexing" ] ENDPOINT= "https://indexing.googleapis.com/v3/urlNotifications:publish" JSON_KEY_FILE = "JSON file path" credentials = ServiceAccountCredentials.from_json_keyfile_name(JSON_KEY_FILE, scopes=SCOPES) http = credentials.authorize(httplib2.Http()) urlList=[“url 1”,”url 2”,”url 3”] for index, item in enumerate(urlList): content = { "url": item, "type": "URL_UPDATED" } response, content = http.request(ENDPOINT, method="POST", body=json.dumps(content)) print(response)
5. Run the Program.
6. Check the output status code. It should be 200. If it’s not, that means there is an issue with authentication or the limit is reached. (Daily limit is 200 requests.)
That’s it. You have successfully requested Google to index your web pages.
Conclusion
Using Google’s Indexing API, you can request Google to index or remove pages from Google Search, ensuring your content appears faster in search results. This is especially useful for websites with frequent content updates.
Try this method and optimize your SEO efforts today!