如何利用自動補全和「人們也問」資料來建構關鍵字研究工具
學習如何建立一個包含自動補全建議和「人們也問」(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 response 額度>>
最佳實踐
開發階段保存原始 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 區塊、比較頁或開發者教學。