
一步步教你進行 Python REST API 身份驗證
批量化監測“百度關鍵詞排名”
自動化腳本替代手動查詢,支持同時抓取數百至數千個關鍵詞的PC/移動端排名。
實時洞察與“排名波動趨勢”
接口返回 position
和 previous_position
,幫助識別快速下跌或算法調整影響。
“競品對比分析”
同時批量查詢多家目標 URL,在同一關鍵詞下直接對比排名差距。
自動化告警腳本
設定“首頁出局”或“日跌 ≥3 名”等閾值,自動推送郵件、Slack 或 Webhook 通知。
“可視化儀表盤搭建”
將排名數據導入 Grafana、Power?BI 或 Tableau,生成實時 SEO 排名監控面板。
服務 | 支持百度排名 | 批量查詢 | 競品對比 | 價格模式 |
---|---|---|---|---|
SE?Ranking API | ? | ? | ? | 按項目/關鍵詞計費 |
DataForSEO | ? | ? | ? | 按調用量計費 |
Dragon Metrics | ? | ? | ? | 套餐制 |
Keyword.com | 部分支持 | ? | ? | 企業級套餐 |
推薦:中大型項目首選 SE?Ranking API,同時對比 DataForSEO 作為備選。
pip install se-ranking-sdk requests pandas matplotlib
API_KEY
和 SECRET_KEY
import requests, pandas as pd
from datetime import datetime
API_URL = "https://api.seranking.com/v2/keywords/ranking"
auth = ("YOUR_API_KEY", "YOUR_SECRET_KEY")
payload = {
"project_id": 98765,
"keywords": ["百度關鍵詞排名", "SEO Rank API 教程"],
"urls": ["https://example.com", "https://competitor.com"],
"se_type": ["desktop_zh", "mobile_zh"],
"location": {"location": 38} # 38 = 中國
}
resp = requests.post(API_URL, json=payload, auth=auth)
results = resp.json().get("results", [])
# 轉為 DataFrame
df = pd.DataFrame(results)
df['updated_at'] = pd.to_datetime(df['updated_at'])
print(df.head())
CREATE TABLE baidu_rankings (
id SERIAL PRIMARY KEY,
project_id INT,
keyword VARCHAR(255),
url VARCHAR(512),
position INT,
previous_position INT,
se_type VARCHAR(32),
location_id INT,
updated_at TIMESTAMP
);
baidu_rankings
keyword
, url
, se_type
position
, previous_position
updated_at
import matplotlib.pyplot as plt
# 僅繪制“百度關鍵詞排名” PC 端趨勢
trend = df[(df['keyword']=="百度關鍵詞排名") & (df['se_type']=="desktop_zh")]
trend.set_index('updated_at')['position'].plot(marker='o')
plt.gca().invert_yaxis()
plt.title("百度關鍵詞排名趨勢")
plt.xlabel("日期")
plt.ylabel("排名")
plt.show()
top10 = df[df['position'] < =10]
sov = top10.groupby('url').size() / df['keyword'].nunique()
print("Top?10 首頁占比:", sov)
import smtplib
from email.mime.text import MIMEText
def send_alert(subject, msg):
msg = MIMEText(msg)
msg['Subject'] = subject
msg['From'] = 'alert@example.com'
msg['To'] = 'seo-team@example.com'
with smtplib.SMTP('smtp.example.com') as srv:
srv.login('user','pass')
srv.send_message(msg)
for r in results:
if r['position'] > 10 or (r['position'] - r['previous_position']) > =3:
send_alert(
f"排名告警:{r['keyword']}({r['url']})",
f"新排名:{r['position']},舊排名:{r['previous_position']}"
)
通過本文的全流程方案,你將掌握使用 SEO Rank API 獲取和監控 百度關鍵詞排名 的完整技術棧,從而為 SEO 優化和運營決策提供強有力的數據支持。立即行動,構建你的自動化排名監測系統!
原文引自YouTube視頻:https://www.youtube.com/watch?v=yeGA1A58rNs