To extract keywords from website pages, you need to answer two different questions. The first is which keywords the page is actually about, which you get from its title, headings and body text using frequency counts, TF-IDF or an extractor like YAKE or KeyBERT. The second is which search queries the URL ranks for. For your own site, Google Search Console shows that when you filter the Performance report by page. For someone else's site, you need a third-party SEO tool's ranking database.
Most "get keywords from website" tools blur these together. This guide keeps them separate, gives you tested Python for on-page extraction, and shows how to pull the real ranking queries for any URL you own.
Two meanings of "keywords on a page"
| Question | Data source | Tells you | Misses |
|---|---|---|---|
| What is this page about? | The page's HTML | Topics and phrases the content emphasises | Whether anyone searches for them |
| What does this URL rank for? | Search Console (yours) or SEO tool databases (anyone's) | Real queries that trigger the page | Topics the page covers but doesn't rank for yet |
The gap between those two lists is where the useful work is. A page that's "about" one thing but ranks for something else usually needs its title, headings or focus adjusted. A page that ranks for nothing it's about has a relevance or quality problem.
Quick manual check: title, H1 and headings
Before running any code, look at the signals the author chose deliberately. Open the page, then paste this into the browser DevTools console:
console.table({
title: document.title,
description: document.querySelector('meta[name="description"]')?.content ?? '(none)',
h1: [...document.querySelectorAll('h1')].map(h => h.textContent.trim()).join(' | '),
});
console.table([...document.querySelectorAll('h2, h3')].map(h => ({
level: h.tagName,
text: h.textContent.trim(),
})));
That gives you the title, meta description, H1 and the full H2/H3 outline in two tables. On a well-built page, the main keyword appears in the title and H1, and the secondary keywords show up in the H2s. If the H1 says one thing and the title says another, you've already found an issue.
Because it runs in the browser, this also works on JavaScript-rendered pages, where a simple HTTP fetch only sees an empty shell.
Check keywords on a page with a free tool
If you don't want to write code, a keyword density checker does the counting for you. Our free keyword density checker accepts a URL or pasted text and reports how often words and phrases appear, which is enough to see what a page emphasises and to spot over-repetition.
Frequency tools are a good first pass. Their weakness is that they can't tell a meaningful phrase from a common one, and they count boilerplate (navigation, footers, cookie banners) as if it were content. The methods below fix both problems.
How to extract keywords from website content with Python
The examples below were run with Python 3.12, requests, beautifulsoup4, scikit-learn 1.9, yake 0.7 and keybert 0.9. The test page was Google's own snippet documentation, so you can reproduce the output.
python3 -m venv .venv && source .venv/bin/activate
pip install requests beautifulsoup4 scikit-learn yake keybert
Step 1: fetch the page and strip boilerplate
Every method depends on clean input. This helper pulls the title, meta description and headings, then removes scripts, navigation, headers, footers, sidebars and forms before extracting the main text:
import re
import requests
from bs4 import BeautifulSoup
HEADERS = {"User-Agent": "Mozilla/5.0 (compatible; keyword-audit/1.0)"}
def fetch_page(url: str) -> dict:
html = requests.get(url, headers=HEADERS, timeout=20).text
soup = BeautifulSoup(html, "html.parser")
desc = soup.find("meta", attrs={"name": "description"})
data = {
"title": soup.title.get_text(strip=True) if soup.title else "",
"description": desc.get("content", "") if desc else "",
"h1": [h.get_text(" ", strip=True) for h in soup.find_all("h1")],
"h2_h3": [h.get_text(" ", strip=True) for h in soup.find_all(["h2", "h3"])],
}
# Drop boilerplate before taking the body text
for tag in soup(["script", "style", "noscript", "nav", "header", "footer", "aside", "form"]):
tag.decompose()
main = soup.find("main") or soup.find("article") or soup.body or soup
text = main.get_text(" ", strip=True)
data["text"] = re.sub(r"\s+", " ", text)
return data
Save it as page_text.py; the other scripts import it. On the test page it returned a title starting "How to Write Meta Descriptions | Google Search Central", the H1 "Control your snippets in search results", eleven H2/H3 headings and about 1,250 words of body text.
Two limits to know. requests only sees server-rendered HTML, so for single-page apps you need a headless browser (Playwright or a scraping service; our Crawl4AI vs Firecrawl comparison covers the options). And the main/article heuristic won't catch every site's breadcrumb or sidebar, so look at the extracted text once before trusting the results.
Step 2: n-gram frequency (what the page repeats)
Counting one-, two- and three-word phrases is the simplest extraction method and surprisingly useful. This version skips phrases that start or end with a stop word, so you get "meta description" instead of "of the":
import re
import sys
from collections import Counter
from sklearn.feature_extraction.text import ENGLISH_STOP_WORDS
from page_text import fetch_page
def tokens(text: str) -> list[str]:
return re.findall(r"[a-z0-9][a-z0-9\-']*[a-z0-9]|[a-z]", text.lower())
def top_ngrams(text: str, n: int, k: int = 10) -> list[tuple[str, int]]:
words = tokens(text)
grams = zip(*(words[i:] for i in range(n)))
counts = Counter(
" ".join(g) for g in grams
# skip phrases that start or end with a stop word ("of the", "how to")
if g[0] not in ENGLISH_STOP_WORDS and g[-1] not in ENGLISH_STOP_WORDS
)
return counts.most_common(k)
if __name__ == "__main__":
page = fetch_page(sys.argv[1])
total = len(tokens(page["text"]))
for n in (1, 2, 3):
print(f"--- top {n}-grams ---")
for phrase, count in top_ngrams(page["text"], n):
print(f"{count:4d} {count / total:6.2%} {phrase}")
Trimmed output on the test page:
--- top 1-grams ---
29 2.33% page
27 2.17% description
24 1.93% meta
22 1.77% content
16 1.29% search
--- top 2-grams ---
9 0.72% description content
8 0.64% meta description
7 0.56% search results
6 0.48% google search
--- top 3-grams ---
10 0.80% meta name description
3 0.24% read more deep
2 0.16% garment open monday-friday
The page is clearly about meta descriptions and search results. Notice the noise too: "meta name description" and "garment open monday-friday" come from HTML code samples and example snippets in the page. If you're analysing documentation, add pre and code to the tags you remove in Step 1.
Step 3: TF-IDF (what makes this page different)
Raw frequency rewards words every page uses. TF-IDF downweights terms that are common across a set of documents and boosts terms that are distinctive to one page. With a single page there's nothing to compare against, so pass the target URL first and a few related pages after it, such as competing pages for the same query or sibling pages on your own site:
import sys
from sklearn.feature_extraction.text import TfidfVectorizer
from page_text import fetch_page
urls = sys.argv[1:] # first URL = your page, the rest = comparison pages
docs = [fetch_page(u)["text"] for u in urls]
vec = TfidfVectorizer(
stop_words="english",
ngram_range=(1, 3),
sublinear_tf=True, # dampen raw repetition
token_pattern=r"(?u)\b[a-zA-Z][a-zA-Z0-9\-]+\b",
)
matrix = vec.fit_transform(docs)
terms = vec.get_feature_names_out()
row = matrix[0].toarray().ravel()
for idx in row.argsort()[::-1][:20]:
print(f"{row[idx]:.3f} {terms[idx]}")
Compared against three sibling Google docs (title links, robots meta tag and core updates), the top terms for the snippet page were:
0.091 meta description
0.088 descriptions
0.079 description
0.075 description content
0.066 snippet
0.063 snippets
0.056 meta descriptions
0.049 read deep
Generic words like "Google" and "search" dropped out because every page in the set uses them. What's left is the page's distinctive topic. This is the best way to check whether two of your own pages are competing for the same keyword: if their TF-IDF top terms overlap heavily, they probably are.
Step 4: YAKE (unsupervised keyphrase extraction)
YAKE scores candidate phrases using statistics from the single document (position, frequency, casing, context), with no training data or comparison set. Lower scores mean more relevant:
import sys
import yake
from page_text import fetch_page
page = fetch_page(sys.argv[1])
extractor = yake.KeywordExtractor(lan="en", n=2, top=15)
# YAKE scores: LOWER is more relevant
for phrase, score in extractor.extract_keywords(page["text"]):
print(f"{score:.4f} {phrase}")
0.0058 Central Documentation
0.0060 Google Search
0.0104 page
0.0118 description
0.0138 meta description
0.0164 search results
0.0173 Search Central
0.0220 snippet
0.0277 meta descriptions
YAKE found the right topic, but the top result is "Central Documentation", from a breadcrumb that survived the cleanup. YAKE gives weight to capitalised phrases that appear early, which is exactly what breadcrumbs and site names are. It's fast and needs no model download, but it's the most sensitive of these methods to dirty input.
Step 5: KeyBERT (semantic keyphrases)
KeyBERT embeds the document and candidate phrases with a sentence-transformer model, then ranks phrases by cosine similarity to the whole document. Higher scores mean more relevant. The first run downloads the model, and installing it pulls in PyTorch, so expect a large install:
import sys
from keybert import KeyBERT
from page_text import fetch_page
page = fetch_page(sys.argv[1])
kw_model = KeyBERT(model="all-MiniLM-L6-v2")
keywords = kw_model.extract_keywords(
page["text"],
keyphrase_ngram_range=(1, 2),
stop_words="english",
use_mmr=True, # Maximal Marginal Relevance: less redundant phrases
diversity=0.3,
top_n=10,
)
# KeyBERT scores: cosine similarity, HIGHER is more relevant
for phrase, score in keywords:
print(f"{score:.3f} {phrase}")
0.663 searches snippets
0.641 snippets search
0.620 snippet search
0.579 snippets primarily
0.574 descriptions snippets
0.534 change snippets
0.497 search results
KeyBERT understood that the page is about snippets, which is semantically correct, but the phrases aren't things people type into Google ("searches snippets"). Raising diversity to 0.7 made it worse in this test, surfacing fragments like "cook eggs" from an example. Use KeyBERT to confirm a page's theme, not to produce target keywords.
Which extraction method should you use?
| Method | Speed | Needs | Strength | Weakness |
|---|---|---|---|---|
| Title/H1/headings | Instant | Browser | Shows deliberate targeting | Says nothing about body content |
| N-gram frequency | Fast | stdlib + stop words | Transparent, easy to explain | Counts boilerplate and code |
| TF-IDF | Fast | scikit-learn + comparison pages | Finds what's distinctive | Needs a sensible comparison set |
| YAKE | Fast | yake |
Single document, no model | Sensitive to breadcrumbs and caps |
| KeyBERT | Slow first run | PyTorch model | Captures meaning | Phrases often aren't real queries |
For SEO work, n-grams plus TF-IDF against the pages that currently rank for your target query gets you about as far as you need. Add KeyBERT when you're checking topical focus across many pages at once.
Find the keywords a URL ranks for in Search Console
On-page extraction tells you what a page says. To check website keywords that actually bring traffic, you need search data. For a site you own, Search Console has it:
- Open Performance → Search results.
- Click + Add filter → Page, choose Exact URL, and paste the URL. Use "URLs containing" to cover a whole folder.
- Open the Queries tab and set the date range to the last three months.
- Sort by impressions to see demand, and by clicks to see what earns traffic.
Search Console shows real queries, but with gaps. Anonymized queries are dropped when you filter by query, so the query rows won't add up to the page total. The UI table also exports at most 1,000 rows.
Pull every query for a page through the API
The Search Analytics API returns up to 25,000 rows per request. This request body lists every query for one URL:
{
"startDate": "2026-08-01",
"endDate": "2026-10-31",
"dimensions": ["query"],
"dimensionFilterGroups": [{
"filters": [{
"dimension": "page",
"operator": "equals",
"expression": "https://example.com/blog/meta-descriptions"
}]
}],
"rowLimit": 25000,
"type": "web"
}
Use "operator": "includingRegex" with an RE2 pattern such as ^https://example\.com/blog/ to cover a section. Google's deep dive on performance data limits notes a ceiling of 50,000 rows per day per site per search type through the API. For larger sites, the BigQuery bulk export is the way past it.
Bing Webmaster Tools has a similar Search Performance report with page and keyword views, which is worth checking if Bing sends you meaningful traffic. For setting up ongoing tracking of these queries, see our guide to checking keyword rankings for free.
Compare what the page says with what it ranks for
Put the two lists side by side:
- On-page keyword, no ranking queries: the page covers a topic Google doesn't associate with it. Strengthen it in the title, H1 or a dedicated section, or accept it's a minor subtopic.
- Ranking query, not in the on-page list: Google sees relevance you aren't emphasising. If the query has demand, give it a heading and a direct answer.
- Two pages with the same top terms and the same queries: likely cannibalisation. Merge them or differentiate their focus.
Find keywords from a URL you don't own
You can't see another site's Search Console data. Your options:
- On-page extraction, using everything above, shows what a competitor's page targets.
- Third-party SEO tools (Ahrefs, Semrush and others) estimate ranking keywords for any URL from their own rank-tracking databases. Free tiers are limited, and the data is modelled, so the list will be incomplete for small sites.
- Manual SERP checks confirm the most important queries one at a time.
We cover the free routes in detail in how to find competitor keywords for free. Before you target any keyword you find this way, check how hard it is to rank for; our explainer on how keyword difficulty is calculated shows what those scores mean.
Frequently Asked Questions
How do I get keywords from a website for free?
For what a page is about, view its title, H1 and headings, then run it through a free keyword density checker or the Python scripts above. For what it ranks for, use Search Console's Performance report filtered by page if you own the site, or a third-party SEO tool's free tier if you don't.
Can I see what keywords a competitor's URL ranks for?
Not from Google directly, since Search Console only shows data for sites you've verified. Third-party tools estimate competitor rankings from their own databases. On-page extraction tells you what the competitor is targeting, which is often just as useful.
What is the difference between TF-IDF and keyword density?
Keyword density is how often a term appears as a share of all words on one page. TF-IDF weighs that frequency against how common the term is across a set of documents, so generic words score low and distinctive ones score high. TF-IDF is better at identifying what makes a page different.
Is KeyBERT better than YAKE for SEO keyword extraction?
Not necessarily. KeyBERT captures meaning better, but in our test it produced phrases nobody searches for. YAKE is faster and needs no model, but it's easily distracted by boilerplate. For SEO, frequency plus TF-IDF against ranking competitors is usually the most practical combination.
Why don't Search Console query rows add up to the page's total clicks?
Search Console drops anonymized queries when you filter or group by query, for privacy reasons. The page-level totals include them, so the sum of query rows is always lower than the total.
Conclusion
To extract keywords from website pages properly, separate what the page says from what it ranks for. Use the title, headings, n-grams and TF-IDF to see what a page emphasises, with YAKE or KeyBERT as extra signals. Then pull the page's real ranking queries from Search Console, through the API if you need more than 1,000 rows. The places where those two lists disagree are where your next on-page improvements are.