Yandex Webmaster API use case.


Yandex search ingine provides very powerfull Webmaster online web interface, but you can get most of it's useful information using Yandex Webmaster API and the power of Python. Then you can transform webmaster data in any easy-to-read format for postprocessing and visualisation.

You will need the same ACCESS_TOKEN, that we got in previous section about Yandex Metrika.

Yandex Webmaster API bot with Python.



Lets start from installing Yandex webmaster API library.


pip install yandex-webmaster-api

Then we should create client instance with your ACCESS_TOKEN.


from yandex_webmaster import YandexWebmaster
client = YandexWebmaster('')

Now we are ready to check available hosts for our credentials, we will need host IDs for the next steps.


hosts = client.get_hosts()
hosts

OUT:
[{'ascii_host_url': 'https://python-code.pro/',
'host_id': 'https:python-code.pro:443',
'main_mirror': None,
'unicode_host_url': 'https://python-code.pro/',
'verified': True},
{'ascii_host_url': 'https://weird-jokes.com/',
'host_id': 'https:weird-jokes.com:443',
'main_mirror': None,
'unicode_host_url': 'https://weird-jokes.com/',
'verified': True}]


Then let's check if certain site is indexed and available for search.


result1 = client.get_host('https:python-code.pro:443')
result1

OUT:
{'ascii_host_url': 'https://python-code.pro/',
'host_data_status': 'OK',
'host_display_name': 'python-code.pro',
'host_id': 'https:python-code.pro:443',
'main_mirror': None,
'unicode_host_url': 'https://python-code.pro/',
'verified': True}


Now we are ready to display popular search queries for you site setting time period.


from datetime import datetime, timedelta
date_from = datetime.now() - timedelta(days=30)
date_to = datetime.now()
result2 = client.get_popular_search_queries('https:python-code.pro:443', date_from, date_to, query_indicator='TOTAL_SHOWS')
result2
Popular queries.


Then let's check status and information about our sitemap file.


result3 = client.get_sitemaps(host_id='https:python-code.pro:443')
result3 

OUT:
{'sitemaps': [{'children_count': 0,
'errors_count': 0,
'last_access_date': '2022-07-31T03:41:57.000+03:00',
'sitemap_id': '0500919e-ba70-32dd-a204-b970a136d873',
'sitemap_type': 'SITEMAP',
'sitemap_url': 'https://python-code.pro/static/img/sitemap.xml',
'sources': ['ROBOTS_TXT', 'WEBMASTER'],
'urls_count': 138}]}


Now let's see site's indexing statistics and check if there are some problems.


result4 = client.get_indexing_stats(host_id='https:weird-jokes.com:443')
result4 

OUT:
{'excluded_pages_count': 0,
'searchable_pages_count': 316,
'site_problems': {},
'sqi': 0}


Checking for site problems known by Yandex.


result5 = client.diagnostic_site(host_id='https:python-code.pro:443')
result5
Site problems.


Check indexing information by pages.


result6 = client.get_indexing_samples(host_id='https:weird-jokes.com:443')
result6
Pages indexing.




See also related topics: