Yandex Wordstat parser: how to collect keywords and search volume
Yandex Wordstat is a key tool for analyzing search demand. It helps you find keywords, check their popularity, and track changes in search trends. Web scraping makes data collection faster. You can use the results for SEO and paid search campaigns.
What is Yandex Wordstat and why scrape it?
Yandex Wordstat is a free tool that provides search query statistics from Yandex. SEO specialists use it to find keywords and build keyword lists. Advertisers use it to plan campaigns in Yandex Direct.
Search volume shows how often users search for a specific keyword during a selected period. By default, Wordstat includes the original phrase, related word forms, and queries with additional words.
You can use special operators to get more precise data. Quotation marks (" ") fix the number of words. The exclamation mark (!) fixes the exact word form. Square brackets ([]) fix the word order.
Scraping helps you collect data for many keywords and track changes in search demand.
Ways to scrape Yandex Wordstat
There are three main ways to collect Wordstat data: manually through the website, through the official Wordstat API, or with a web scraper.
Manual collection works well for a small number of keywords. The official Wordstat API provides structured data, but it can be expensive for large tasks. Web scraping tools such as Browser API offer another way to automate data collection.
Browser API: a tool for web scraping
2Captcha Browser API lets you automate web scraping with a cloud browser. It supports dynamic websites and connections through CDP. You can also use an existing Yandex session to access pages that require login.
You can use Python to process the collected data, extract keywords and search volume, and save the results to CSV files.
You must test access to Wordstat statistics before using the scraper for large tasks.
How to scrape Yandex Wordstat with 2Captcha Browser API
2Captcha Browser API lets you automate data collection from Yandex Wordstat. It runs a browser in the cloud. You can control the browser with Playwright or Puppeteer.
Browser API supports cookie imports and authenticated sessions. You can enter search queries, select regions, and download statistics as CSV files.
You do not need to install Chrome on your server or manage your own browser setup.
We will create a Python scraper that performs five tasks:
- Connect to a 2Captcha cloud browser.
- Use an authenticated Yandex session.
- Submit search queries to Wordstat.
- Download statistics from the Top Queries section.
- Save the results as CSV files.
How to set up a Yandex Wordstat scraper in Python
You need 2Captcha and Yandex accounts, Python, and the Playwright library.
First, we will set up the browser and authentication. Then we will create a Python script to collect the data.
Step 1. Create a browser profile
Open 2Captcha Browser API and go to your dashboard.
You can use the Default profile for your first connection. For regular scraping, create a separate profile. You can also configure a proxy and select a country if needed.
Copy the CDP URL from your profile settings. This URL connects your Python script to the cloud browser.
The CDP URL contains access credentials. Do not publish it in public repositories or share it with others.
Step 2. Log in to Yandex Wordstat with cookies
You must log in to your Yandex account to use Yandex Wordstat.
Browser API supports cookie imports. This lets you use an existing login session in the cloud browser.
Follow these steps:
- Open Yandex Wordstat and log in to your account.
- Export your session cookies in JSON format.
- Save them to a file named
cookies.json. - Import the file into your 2Captcha browser profile.
Use this API endpoint to import cookies:
POST https://cb-api.2captcha.com/cookies/import-cookies
The request requires two parameters:
- connectionUri — the CDP URL of your browser profile.
- cookiesText — the contents of your cookies file.
After a successful import, Browser API prepares the cookies for your next connection.
If your session is still valid, Yandex may open Wordstat without asking you to log in again. In some cases, Yandex may require a new login.
For details, see the Cookie Import API documentation.
Step 3. Install Playwright
We will use Playwright to control the browser. This Python library can open pages, enter text, click buttons, and download files.
Install Playwright with this command:
pip install playwright
You do not need to install Chrome locally. 2Captcha runs the browser in the cloud. Playwright connects to it through CDP.
Step 4. Create a Wordstat scraper in Python
Create a file named wordstat_parser.py.
In this example, we will collect statistics for three search queries:
- apartment renovation
- kitchen renovation
- bathroom renovation
The script opens Wordstat and submits each query. It then downloads the results from the Top Queries section.
The program saves a separate CSV file for each keyword.
import json
import os
import re
from pathlib import Path
from urllib.error import HTTPError, URLError
from urllib.request import Request, urlopen
from playwright.sync_api import TimeoutError as PlaywrightTimeoutError
from playwright.sync_api import sync_playwright
WORDSTAT_URL = "https://wordstat.yandex.ru/"
COOKIE_IMPORT_URL = "https://cb-api.2captcha.com/cookies/import-cookies"
KEYWORDS = [
"apartment renovation",
"kitchen renovation",
"bathroom renovation",
]
OUTPUT_DIR = Path("wordstat_results")
CDP_URL = os.environ.get("BROWSER_API_CDP_URL")
def import_cookies():
cookie_file = Path("cookies.json")
if not cookie_file.exists():
return
request = Request(
COOKIE_IMPORT_URL,
data=json.dumps({
"connectionUri": CDP_URL,
"cookiesText": cookie_file.read_text(encoding="utf-8"),
}).encode("utf-8"),
headers={"Content-Type": "application/json"},
method="POST",
)
try:
with urlopen(request, timeout=45) as response:
result = json.load(response)
except HTTPError as exc:
details = exc.read().decode("utf-8", errors="replace")
raise RuntimeError(
f"Failed to import cookies: {details}"
) from exc
except URLError as exc:
raise RuntimeError(
f"Cookie import service is unavailable: {exc}"
) from exc
if not result.get("cookiesStaged"):
raise RuntimeError(f"Cookies were not accepted: {result}")
print(f"Cookies prepared: {result['cookiesStaged']}")
def first_visible(*locators):
for locator in locators:
try:
locator.first.wait_for(state="visible", timeout=3000)
return locator.first
except PlaywrightTimeoutError:
continue
raise RuntimeError("Page element not found")
def export_keyword(page, keyword, index):
page.goto(
WORDSTAT_URL,
wait_until="domcontentloaded",
timeout=60000,
)
if "passport.yandex" in page.url:
raise RuntimeError(
"Yandex authentication is required"
)
# Match the original Russian labels in Wordstat.
tab = first_visible(
page.get_by_text("Топы запросов", exact=True),
page.get_by_text("Топ запросов", exact=True),
)
tab.click()
field = first_visible(
page.get_by_placeholder(
"Введите слово или словосочетание"
),
page.locator('input[placeholder*="слово"]'),
page.locator('input[type="search"]'),
)
field.fill(keyword)
field.press("Enter")
try:
page.wait_for_load_state("networkidle", timeout=15000)
except PlaywrightTimeoutError:
pass
download_button = first_visible(
page.get_by_role("button", name="Скачать"),
page.get_by_text("Скачать", exact=True),
)
with page.expect_download(timeout=60000) as download_info:
download_button.click()
try:
page.get_by_text(
re.compile(r"Таблицу\s*\(CSV\)|^CSV$", re.I)
).first.click(timeout=2000)
except PlaywrightTimeoutError:
pass
download = download_info.value
if not download.suggested_filename.lower().endswith(".csv"):
raise RuntimeError(
"The downloaded file is not in CSV format"
)
name = re.sub(r"[^\w-]+", "_", keyword).strip("_")
output = OUTPUT_DIR / f"{index:03d}_{name}.csv"
download.save_as(output)
print(f"Saved: {output}")
def main():
if not CDP_URL:
raise SystemExit(
"Set the BROWSER_API_CDP_URL environment variable"
)
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
import_cookies()
failures = 0
with sync_playwright() as playwright:
browser = playwright.chromium.connect_over_cdp(
CDP_URL,
timeout=60000,
)
try:
context = browser.contexts[0]
page = context.new_page()
for index, keyword in enumerate(KEYWORDS, start=1):
try:
export_keyword(page, keyword, index)
except Exception as exc:
failures += 1
print(f"Error processing '{keyword}': {exc}")
try:
page.screenshot(
path=str(
OUTPUT_DIR / f"error_{index}.png"
)
)
except Exception:
pass
finally:
browser.close()
if failures:
raise SystemExit(
f"Failed queries: {failures}"
)
if __name__ == "__main__":
main()
The script uses Browser API and Playwright to connect to a browser and automate data collection.
Important: This example has not been tested with a live, authenticated Wordstat session. Yandex may change its page layout and button names. Check the Playwright selectors and CSV downloads before using the script.
Step 5. Run the scraper
Before you run the script, save your CDP URL in the BROWSER_API_CDP_URL environment variable.
If the cookies.json file is in the same folder, the script imports the cookies. Otherwise, it uses the current state of the browser profile.
Run the script:
python wordstat_parser.py
After a successful run, the script creates a folder named wordstat_results. This folder contains a CSV file for each query.
wordstat_results/
├── 001_apartment_renovation.csv
├── 002_kitchen_renovation.csv
└── 003_bathroom_renovation.csv
You can open these files in Excel or Google Sheets. You can also process the data with Python.
How to automate keyword collection at scale
To collect more keywords, add your search phrases to the KEYWORDS list. You can also load them from a CSV or text file.
The scraper processes each query and saves the results. You can then combine the files into one table.
Remove duplicate keywords and sort the results by search volume. This will help you build a clean keyword list for SEO.
You can also run the scraper on a schedule. For example, run it once a week or once a month. This helps you track changes in search demand.
A Browser API session can run for up to 30 minutes. Split large keyword lists into smaller batches. Save your results after each run.
You must also follow Yandex's rules and limits for automated data collection.
How to scrape regional data and search trends
Yandex Wordstat provides more than keyword statistics. It also shows regional search data and changes in demand over time.
Regional search statistics
The Regions section lets you compare search demand across cities and regions. It shows the number of searches, their share, and the regional interest index.
This data is useful for local SEO. It can help you select regions for marketing campaigns.
Search volume trends
The Dynamics section shows how search volume changes over time. You can view data by day, week, or month.
This helps you find seasonal keywords and track changes in user interest.
Both sections support CSV exports.
You can use Playwright to switch between these sections, select filters, and download files. To do this, add the required browser actions to your script.
Common Yandex Wordstat scraping errors
Authentication errors. Your cookies may expire. If this happens, Yandex may ask you to log in again. Export new cookies and import them into Browser API.
Search statistics do not load. Check your browser connection and make sure Wordstat is available. Also check for access limits set by Yandex.
The script cannot find page elements. Yandex may change its website layout. If a button or input field changes, update the Playwright selectors.
CSV download fails. Make sure the search results have loaded. Check that the CSV format is selected. You may need to select it after clicking the Download button.
The browser connection closes. Browser API sessions have a 30-minute limit. Split large jobs into smaller runs. Save your data after each query.
Frequently asked questions
Can I scrape Yandex Wordstat for free?
The Yandex Wordstat website is free to use. However, 2Captcha Browser API is a paid service. The official Wordstat API also has separate usage fees.
Can I collect search volume without logging in?
No. You must log in to your Yandex account to access statistics through the Wordstat website. Browser API can use an existing authenticated session through cookies.
Can I scrape Wordstat data by region?
Yes. Wordstat lets you select cities and regions. You can use Playwright to automate region selection and download the results.
What is the difference between Browser API and Wordstat API?
The official Wordstat API returns structured data through API requests. Browser API controls a web browser and works with the Wordstat website.
With Browser API, your script can enter queries, select filters, and export data just as a user would.
Do I need Selenium to scrape Wordstat?
No. Browser API supports Playwright, Puppeteer, and other tools that use CDP connections. For this example, you only need Python and Playwright.
Conclusion
Yandex Wordstat scraping helps you collect keywords and search volume data faster. You can use this data for SEO, keyword research, and paid search campaigns.
2Captcha Browser API lets you automate this process with a cloud browser. It supports authenticated sessions, cookie imports, and Playwright.
You can collect Wordstat data without installing Chrome or managing your own browser infrastructure.
0 Comments
Would you like to join the discussion? To continue, you'll need to log in.