Python Examples

To speed up indexing, there are different tools, in addition to the default sitemap.xml, you can add automatic sending of a new link to search engines, in this article we will consider two examples: Google Index API and Yandex IndexNow

Yandex

As in Bing, a convenient IndexNow protocol is used; in order for the API to accept the link, it is necessary to generate a random key and place it on the server:
IndexNow | Bing Webmaster Tools

View key: be7dc003835e410797c70ed0ee62930d
Should be stored: https://yourdomain.cc/be7dc003835e410797c70ed0ee62930d.txt

Now you can send links as a list to the address https://yandex.com/indexnow

js = {
'host': 'yourdomain.cc',
'key': 'be7dc003835e410797c70ed0ee62930d',
'keyLocation': 'https://yourdomain.cc/be7dc003835e410797c70ed0ee62930d.txt,
'urlList':[
'https://yourdomain.cc/mynewpage.html',
'https://yourdomain.cc/fastindex.html',
]
}

r = requests.post('https://yandex.com/indexnow', headers={'Content-Type': 'application/json', 'charset': 'utf-8'}, json=js)
print(r.content)

If everything is correct, we will receive the following in response: {'success':true}

From my own experience, I can say that Yandex reacts very quickly, literally the next minute the Bot visits the received pages, so this method is probably even faster than indexing by Metrica, RSS feed, etc.

Google

In Google, unlike Bing and Yandex no protocol IndexNowso it's a little more difficult to organize the sending of new pages, for this you will need the following:
Create a new project in Google Cloud: https://console.cloud.google.com/projectcreate

Create

Create

Create a service account:

Create Service Account

Create Service Account

In the second step, select the Owner role!

In the second step, select the Owner role!

Copy the Email - testid@...gserviceaccount.com, you will need it later in GSC

Copy the Email – testid@…gserviceaccount.com, you will need it later in GSC

Create a new key and download it in the format JSON.

Also, you need to add the created service account as Owner in Google Search Console:

When adding, specify the email of the service account.

When adding, specify the email of the service account.

You can now submit pages for indexing via API.
Python function I use for convenience in PasteBin: pastebin.com/raw/rp8MxeaK

(In theory, you can send several links at once, whoever tells you how, gets a + in karma, but I send one at a time, in general, the limit is 200 links per day, but in my experience Google is reluctant to index even these 200 links, maybe you will have a better result, write in the comments.)

The first request may result in an error: {\n "error": {\n "code": 403,\n "message": "Web Search Indexing API has not been used in project 559582583376 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/indexing.googleapis.com/overview?project=559582583376 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",\n "status": "PERMISSION_DENIED"

In this case, you need to visit the specified link and click Enable.

If everything is correct, Google will respond something like this:

b'{\n "urlNotificationMetadata": {\n "url": "https://yourdomain.cc/fastindex.html/",\n "type": "URL_UPDATED",\n "notifyTime": "2024-08-11T19:22:32.866322520Z"\n }\n }\n}\n'

That's all I have for now, thank you for your attention.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *