如何利用自动补全和“人们也问”数据构建关键词研究工具
学习如何构建一个包含自动补全建议和“人们也问”(People Also Ask)数据的关键词研究工具。利用 Python 收集关键词灵感、问题及意图信号,并将结果导出为 CSV 格式。
快速回答: 你可以把自动补全建议和 People Also Ask(PAA,“其他用户还问了”)问题结合起来,构建一个关键词研究工具。自动补全适合扩展长尾关键词,PAA 则能揭示问题型搜索意图。通过 SERP API 获取这些搜索信号后,再用 Python 整理成 CSV,就能用于 SEO 规划、内容大纲或 AI 工作流。
关键词研究不只是看搜索量。
用户在搜索时,会通过输入的词、看到的搜索建议,以及搜索结果中出现的相关问题,透露自己的搜索意图。
两个很有用的数据来源是:
-
自动补全数据:基于种子关键词的搜索建议
-
People Also Ask 数据:与查询相关的问题型搜索结果
把两者结合起来,可以帮你找到长尾关键词、FAQ 问题、内容角度和搜索意图模式。
数据层可以使用 Talordata SERP API,或其他能返回结构化搜索结果的 SERP API。Talordata 产品页说明,其 SERP API 可提供 Google 和主要搜索引擎的实时结构化搜索数据,并支持 JSON / HTML 输出和地理定位能力。
为什么自动补全和 People Also Ask 很重要?
自动补全和 People Also Ask 回答的是不同问题。
|
数据来源 |
可以帮你找到什么 |
|
自动补全 |
用户可能输入的长尾关键词变体 |
|
People Also Ask |
用户点击结果前可能会问的问题 |
|
自然搜索摘要 |
当前排名页面如何描述主题 |
|
相关搜索 |
额外的主题群组 |
例如,从种子关键词:
serp api
自动补全可能返回:
serp api pricing
serp api python
serp api for seo
serp api alternatives
serp api for ai agents
People Also Ask 可能返回:
What is a SERP API?
How do SERP APIs work?
Is it legal to scrape search results?
What is the best API for Google search results?
自动补全告诉你用户可能会输入什么,People Also Ask 告诉你用户可能想理解什么。
我们要构建什么?
我们会建立一个 Python 流程:
种子关键词
→ 采集自动补全建议
→ 采集 People Also Ask 问题
→ 整理关键词候选词
→ 分类搜索意图
→ 导出为 CSV
最终 CSV 可以包含:
|
字段 |
含义 |
|
|
原始种子关键词 |
|
|
采集到的关键词或问题 |
|
|
自动补全或 PAA |
|
|
信息型、商业型、技术型、本地型或通用型 |
|
|
关键词字数 |
|
|
建议内容形式 |
|
|
采集时间 |
Step 1:设置环境变量
不要把密钥直接写进代码。
export TALORDATA_API_KEY="your_api_key_here"
export TALORDATA_SERP_ENDPOINT="your_talordata_serp_endpoint_here"
Windows PowerShell:
$env:TALORDATA_API_KEY="your_api_key_here"
$env:TALORDATA_SERP_ENDPOINT="your_talordata_serp_endpoint_here"
安装依赖:
pip install requests
请使用 Talordata 后台或 API 文档中显示的端点和参数。Talordata 文档提供 SERP API 流程的查询参数说明。
Step 2:建立请求辅助函数
把请求层和解析逻辑分开,后续更容易调整。
import os
import requests
def require_env(name):
value = os.getenv(name)
if not value:
raise RuntimeError(f"Missing required environment variable: {name}")
return value
TALORDATA_API_KEY = require_env("TALORDATA_API_KEY")
TALORDATA_SERP_ENDPOINT = require_env("TALORDATA_SERP_ENDPOINT")
def call_serp_api(payload):
headers = {
"Authorization": f"Bearer {TALORDATA_API_KEY}",
"Content-Type": "application/json"
}
response = requests.post(
TALORDATA_SERP_ENDPOINT,
json=payload,
headers=headers,
timeout=30
)
response.raise_for_status()
return response.json()
有些 API 使用 GET,也有些会把 API key 放在查询参数中。如果你的设置不同,只需要修改这个辅助函数。
Step 3:采集自动补全建议
不同 API 的自动补全响应可能使用不同字段名称,所以这里支持几种常见格式。
def fetch_autocomplete(seed_keyword, location="United States", language="en"):
payload = {
"engine": "google_autocomplete",
"q": seed_keyword,
"location": location,
"hl": language,
"output": "json"
}
return call_serp_api(payload)
def extract_autocomplete_keywords(response_json):
raw_items = (
response_json.get("suggestions")
or response_json.get("autocomplete_results")
or response_json.get("completion_results")
or []
)
keywords = []
for item in raw_items:
if isinstance(item, str):
keywords.append(item)
elif isinstance(item, dict):
keyword = item.get("value") or item.get("suggestion") or item.get("keyword")
if keyword:
keywords.append(keyword)
return keywords
如果你的 API 使用其他引擎名称,例如 autocomplete 或 google_suggest,修改 engine 的值即可。
Step 4:采集 People Also Ask 问题
People Also Ask 数据通常来自普通 Google 搜索响应,可能出现在 related_questions、people_also_ask 或 paa_results 等字段下。
def fetch_google_search(query, location="United States", language="en", country="us"):
payload = {
"engine": "google",
"q": query,
"location": location,
"hl": language,
"gl": country,
"num": 10,
"output": "json"
}
return call_serp_api(payload)
def extract_paa_questions(response_json):
raw_items = (
response_json.get("related_questions")
or response_json.get("people_also_ask")
or response_json.get("paa_results")
or []
)
questions = []
for item in raw_items:
if isinstance(item, str):
questions.append(item)
elif isinstance(item, dict):
question = item.get("question") or item.get("title")
if question:
questions.append(question)
return questions
PAA 问题很适合用于 FAQ 区块、解释型文章、比较页和内容大纲。
Step 5:分类搜索意图
第一版不需要复杂模型,简单规则就可以先用起来。
def classify_intent(keyword):
text = keyword.lower()
if any(word in text for word in ["what", "why", "how", "guide", "tutorial"]):
return "informational"
if any(word in text for word in ["best", "top", "vs", "alternative", "compare"]):
return "commercial"
if any(word in text for word in ["price", "pricing", "cost", "free trial"]):
return "commercial"
if any(word in text for word in ["api", "python", "docs", "integration", "example"]):
return "technical"
if any(word in text for word in ["near me", "local", "map", "maps"]):
return "local"
return "general"
这不会完全准确,但可以先形成一个可用的分组层。
Step 6:建议内容角度
接着根据关键词推荐简单的内容形式。
def suggest_content_angle(keyword, source):
intent = classify_intent(keyword)
if source == "paa":
return "FAQ section or explainer paragraph"
if intent == "technical":
return "Developer tutorial"
if intent == "commercial":
return "Comparison or buying guide"
if intent == "local":
return "Local SEO landing page or local report"
if intent == "informational":
return "Educational blog post"
return "Topic cluster supporting page"
这样输出的结果对 SEO 和内容团队会更有用。
Step 7:导出关键词候选词到 CSV
import csv
from datetime import datetime, timezone
CSV_COLUMNS = [
"seed_keyword",
"keyword",
"source",
"intent",
"word_count",
"content_angle",
"collected_at"
]
def clean_text(value):
if not value:
return ""
return " ".join(str(value).split())
def build_rows(seed_keyword, keywords, source):
collected_at = datetime.now(timezone.utc).isoformat()
rows = []
for keyword in keywords:
cleaned = clean_text(keyword)
if not cleaned:
continue
rows.append({
"seed_keyword": seed_keyword,
"keyword": cleaned,
"source": source,
"intent": classify_intent(cleaned),
"word_count": len(cleaned.split()),
"content_angle": suggest_content_angle(cleaned, source),
"collected_at": collected_at
})
return rows
def dedupe_rows(rows):
seen = set()
unique_rows = []
for row in rows:
key = row["keyword"].lower()
if key in seen:
continue
seen.add(key)
unique_rows.append(row)
return unique_rows
def export_to_csv(rows, filename="keyword_research_results.csv"):
if not rows:
print("No keyword ideas found.")
return
with open(filename, mode="w", newline="", encoding="utf-8") as file:
writer = csv.DictWriter(file, fieldnames=CSV_COLUMNS)
writer.writeheader()
writer.writerows(rows)
print(f"Exported {len(rows)} keyword ideas to {filename}")
完整 Python 示例
import os
import csv
import requests
from datetime import datetime, timezone
CSV_COLUMNS = [
"seed_keyword",
"keyword",
"source",
"intent",
"word_count",
"content_angle",
"collected_at"
]
def require_env(name):
value = os.getenv(name)
if not value:
raise RuntimeError(f"Missing required environment variable: {name}")
return value
TALORDATA_API_KEY = require_env("TALORDATA_API_KEY")
TALORDATA_SERP_ENDPOINT = require_env("TALORDATA_SERP_ENDPOINT")
def call_serp_api(payload):
headers = {
"Authorization": f"Bearer {TALORDATA_API_KEY}",
"Content-Type": "application/json"
}
response = requests.post(
TALORDATA_SERP_ENDPOINT,
json=payload,
headers=headers,
timeout=30
)
response.raise_for_status()
return response.json()
def fetch_autocomplete(seed_keyword, location="United States", language="en"):
payload = {
"engine": "google_autocomplete",
"q": seed_keyword,
"location": location,
"hl": language,
"output": "json"
}
return call_serp_api(payload)
def fetch_google_search(query, location="United States", language="en", country="us"):
payload = {
"engine": "google",
"q": query,
"location": location,
"hl": language,
"gl": country,
"num": 10,
"output": "json"
}
return call_serp_api(payload)
def clean_text(value):
if not value:
return ""
return " ".join(str(value).split())
def extract_autocomplete_keywords(response_json):
raw_items = (
response_json.get("suggestions")
or response_json.get("autocomplete_results")
or response_json.get("completion_results")
or []
)
keywords = []
for item in raw_items:
if isinstance(item, str):
keywords.append(item)
elif isinstance(item, dict):
keyword = item.get("value") or item.get("suggestion") or item.get("keyword")
if keyword:
keywords.append(keyword)
return keywords
def extract_paa_questions(response_json):
raw_items = (
response_json.get("related_questions")
or response_json.get("people_also_ask")
or response_json.get("paa_results")
or []
)
questions = []
for item in raw_items:
if isinstance(item, str):
questions.append(item)
elif isinstance(item, dict):
question = item.get("question") or item.get("title")
if question:
questions.append(question)
return questions
def classify_intent(keyword):
text = keyword.lower()
if any(word in text for word in ["what", "why", "how", "guide", "tutorial"]):
return "informational"
if any(word in text for word in ["best", "top", "vs", "alternative", "compare"]):
return "commercial"
if any(word in text for word in ["price", "pricing", "cost", "free trial"]):
return "commercial"
if any(word in text for word in ["api", "python", "docs", "integration", "example"]):
return "technical"
if any(word in text for word in ["near me", "local", "map", "maps"]):
return "local"
return "general"
def suggest_content_angle(keyword, source):
intent = classify_intent(keyword)
if source == "paa":
return "FAQ section or explainer paragraph"
if intent == "technical":
return "Developer tutorial"
if intent == "commercial":
return "Comparison or buying guide"
if intent == "local":
return "Local SEO landing page or local report"
if intent == "informational":
return "Educational blog post"
return "Topic cluster supporting page"
def build_rows(seed_keyword, keywords, source):
collected_at = datetime.now(timezone.utc).isoformat()
rows = []
for keyword in keywords:
cleaned = clean_text(keyword)
if not cleaned:
continue
rows.append({
"seed_keyword": seed_keyword,
"keyword": cleaned,
"source": source,
"intent": classify_intent(cleaned),
"word_count": len(cleaned.split()),
"content_angle": suggest_content_angle(cleaned, source),
"collected_at": collected_at
})
return rows
def dedupe_rows(rows):
seen = set()
unique_rows = []
for row in rows:
key = row["keyword"].lower()
if key in seen:
continue
seen.add(key)
unique_rows.append(row)
return unique_rows
def export_to_csv(rows, filename="keyword_research_results.csv"):
if not rows:
print("No keyword ideas found.")
return
with open(filename, mode="w", newline="", encoding="utf-8") as file:
writer = csv.DictWriter(file, fieldnames=CSV_COLUMNS)
writer.writeheader()
writer.writerows(rows)
print(f"Exported {len(rows)} keyword ideas to {filename}")
if __name__ == "__main__":
seed_keyword = "serp api"
location = "United States"
autocomplete_json = fetch_autocomplete(seed_keyword, location=location)
autocomplete_keywords = extract_autocomplete_keywords(autocomplete_json)
search_json = fetch_google_search(seed_keyword, location=location)
paa_questions = extract_paa_questions(search_json)
rows = []
rows.extend(build_rows(seed_keyword, autocomplete_keywords, "autocomplete"))
rows.extend(build_rows(seed_keyword, paa_questions, "paa"))
rows = dedupe_rows(rows)
export_to_csv(rows)
执行后会得到:
keyword_research_results.csv
输出示例
seed_keyword,keyword,source,intent,word_count,content_angle,collected_at
serp api,serp api pricing,autocomplete,commercial,3,Comparison or buying guide,2026-06-22T00:00:00Z
serp api,serp api python,autocomplete,technical,3,Developer tutorial,2026-06-22T00:00:00Z
serp api,What is a SERP API?,paa,informational,5,FAQ section or explainer paragraph,2026-06-22T00:00:00Z
serp api,How do SERP APIs work?,paa,informational,5,FAQ section or explainer paragraph,2026-06-22T00:00:00Z
接下来可以把 CSV 导入 Google Sheets、Airtable、Notion、数据库或 AI 内容规划流程。
如何用输出结果做 SEO 规划?
可以按搜索意图分组:
|
搜索意图 |
适合的内容形式 |
|
信息型 |
博客文章、解释文、指南 |
|
商业型 |
比较页、替代方案页、选购指南 |
|
技术型 |
开发者教程、API 文档、集成指南 |
|
本地型 |
本地 SEO 落地页、区域报告 |
|
PAA 问题 |
FAQ 区块、H2 小节、内容大纲问题 |
例如,输出结果可以变成这样的内容大纲:
Topic: SERP API
Main angle: Developer tutorial
Supporting questions:
- What is a SERP API?
- How do SERP APIs work?
- Can I use a SERP API with Python?
Suggested sections:
- What the API returns
- Query parameters
- Python example
- CSV export
- FAQ
如果使用 Talordata SERP API,可以把这套结构扩展到普通 Google 搜索结果、People Also Ask 问题、自动补全建议、相关搜索,以及你所选端点返回的其他搜索结果模块。Talordata 将 SERP API 使用场景定位于 SEO 监控、市场研究、广告验证、竞争情报和 AI 工作流等方向。免费领取1000次API响应额度>>
最佳实践
开发阶段保存原始 API 响应。自动补全和 PAA 响应结构可能会因查询、地区和供应商不同而变化。
保持请求层和解析逻辑分离,后续更容易调整 API 端点。
不要只依赖自动补全。它能提供关键词变体,但单独使用上下文不足。
不要只依赖 People Also Ask。它能提供有用问题,但不能取代完整搜索结果分析。
追踪地区和语言。搜索建议和 PAA 问题可能因国家、城市和语言而变化。
搜索量可以后续再加。自动补全和 PAA 适合做发现,搜索量和排名难度是另一层指标。
FAQ
自动补全和 People Also Ask 有什么不同?
自动补全显示用户可能输入的搜索建议。People Also Ask 显示用户可能想理解的问题型结果。
可以用 Python 构建关键词研究工具吗?
可以。你可以用 Python 采集自动补全建议和 People Also Ask 问题,整理结果、分类搜索意图,并导出关键词候选词到 CSV。
什么是 PAA 数据?
PAA 是 People Also Ask 的缩写,指 Google 搜索结果中常见的问题型结果。这些问题很适合用于 FAQ 区块、内容大纲和搜索意图分析。
自动补全数据足够做关键词研究吗?
不够。自动补全适合发现关键词变体,但最好结合搜索结果数据、People Also Ask 问题、搜索量和竞品分析。
这个流程可以用来生成内容大纲吗?
可以。你可以按搜索意图分组自动补全关键词和 PAA 问题,然后转成文章大纲、FAQ 区块、比较页或开发者教程。