Indexation of urls in bulk via API with XML Sitemap
Indexation via API of urls in bulk using existing Sitemap:
The Indexing API empowers site owners to promptly inform Google about page additions or removals, facilitating timely crawls for enhanced user traffic quality. Staying ahead of competitors is crucial, ensuring your site is crawled and ranked promptly, especially for time-sensitive, competitive content.
While Google initially suggests the Indexing API solely for JobPosting or BroadcastEvent embedded in VideoObject websites, our tests revealed its effectiveness across various website types.
Below are the steps to submit URLs from sitemaps for indexing.
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.
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
4. Execution of code:
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 fwd slash, # Replace 'your_website_url' with your actual website URL:
import json
from google.oauth2 import service_account
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
# Replace 'path/to/credentials.json' with the path to your downloaded JSON key file
credentials_path = 'path/to/credentials.json'
# Authenticate using the service account credentials
credentials = service_account.Credentials.from_service_account_file(
credentials_path,
scopes=['https://www.googleapis.com/auth/webmasters']
)
try:
# Create a Search Console service
search_console_service = build('webmasters', 'v3', credentials=credentials)
# Replace 'your_website_url' with your actual website URL
website_url = 'your_website_url'
# Get a list of all the sitemaps for the specified site
sitemap_list = search_console_service.sitemaps().list(siteUrl=website_url).execute()
# Loop through each sitemap and submit all URLs for indexing
for sitemap in sitemap_list.get('sitemap', []):
sitemap_url = sitemap['path']
# Submit the sitemap for indexing
search_console_service.sitemaps().submit(siteUrl=website_url, feedpath=sitemap_url).execute()
print(f"Sitemap {sitemap_url} submitted for indexing.")
print("Indexing process completed successfully.")
except HttpError as e:
# Handle HTTP errors
print(f"HTTP error occurred: {e}")
except Exception as e:
# Handle other types of exceptions
print(f"An unexpected error occurred: {e}")
else:
# This block runs if there are no exceptions
print("Script ran without errors.")
5. To Run the script:
Save the above script with a .py extension (e.g., index_webpages.py) on desktop and execute it using the following command: python name of file.py
It will show success message with list of sitemaps added for indexation.
Please share your experiences in comment section.
2/06/2024 06:59:00 PM
|
Contents
A One Step Solution,
SEO
|
Most Viewed Posts from hbari.blogspot.com
-
TOP 10 TIPS for Writng Article Effectively: On the Internet “content is king”, and the real guts of content is the written word. If yo...
-
Swastika: What Does This Symbol Actual Mean? The Swastika (from Sanskrit svastika) is an equilateral cross its arms bent at right ang...
-
8 SEO Myths Debunked : One of my favorite pastimes is debunking SEO myths – and there are many! I could probably come up with 100 SEO-rela...
-
If you write articles doing keyword research with Google Adwords can help you make extra money. By using Google Adwords keyword tool you...
-
Interaction to Next Paint (INP) is a crucial web performance metric that directly impacts user experience. Let's dive into what INP is, ...
-
Choosing and Using the Right Web Host : Click Here : For Cheapest Domain And Hosting Plans Your Host is Your Foundation ...
-
DRINK WATER ON EMPTY STOMACH It is popular in Japan today to drink water immediately after waking up every morning. Furthermore, scientifi...
-
Quantum computers come a step closer to reality Washington, September 30 (ANI): University of Michigan physicists have created the first ato...
-
In the ever-evolving landscape of search engine optimization (SEO), staying ahead of the curve is paramount for businesses looking to maximi...
Blog Visits
HVBARI Blog's Content
Popular Posts
SEO contents
About Me
- HITENDRA V BARI
- MY NAME IS HITENDRA V BARI. Masters in Physics and then working as a Digital Marketing Manager (SEO, SEM, SMM and Research analyst). I'm regular , parttime blogger like to blogs on various trending, on going topics but in different way. One of my biggest dream is that to give speech on stage, with a lakhs of people viewing me live around the world.
0 comments:
Post a Comment