原始 Alexa API 方案 (已廢止)
歷史參考:Alexa 曾提供 https://data.alexa.com/data/?cli=10&dat=snba&ver=7.0&url={domain} 回傳 XML,包含 <POPULARITY TEXT="12345"/> 節點。解析代碼:
<?php
function getAlexaRank($domain) {
$url = "https://data.alexa.com/data/?cli=10&dat=snba&ver=7.0&url=" . urlencode($domain);
$xml = @simplexml_load_file($url);
if ($xml && isset($xml->POPULARITY['TEXT'])) {
return (int)$xml->POPULARITY['TEXT'];
}
return 0;
}
重要提醒:Amazon 已於 2022 年 5 月 1 日關閉 Alexa Internet 服務,此 API 不再可用,歷史數據亦不可獲取。
現代替代方案:第三方 SEO 數據 API
| 服務商 | API 端點範例 | 免費額度 | 特色 |
| SimilarWeb | api.similarweb.com/v1/website/{domain}/total-traffic-and-engagement | 付費 | 流量估算、來源分析、關鍵字 |
| Semrush | api.semrush.com/analytics/v1/ | 付費 | 關鍵字排名、反向連結、廣告研究 |
| Ahrefs | apiv2.ahrefs.com | 付費 | 反向連結、關鍵字、內容缺口 |
| DataForSEO | api.dataforseo.com/v3/ | 按量付費 | SERP、關鍵字、流量估算,適合開發者整合 |
| Moz Links API | lsapi.seomoz.com/v2/ | 付費 | Domain Authority、Spam Score |
自建指標估算方案 (無外部依賴)
若無預算呼叫付費 API,可自行收集公開指標構建「站點權重評分」:
<?php
function estimateSiteScore($domain) {
$score = 0;
// 1. HTTPS 支援 (+10)
if (@fopen("https://$domain", 'r')) $score += 10;
// 2. 頁面載入速度 (使用 get_headers 粗略估測)
$start = microtime(true);
@get_headers("https://$domain");
$latency = (microtime(true) - $start) * 1000;
if ($latency < 500) $score += 20;
elseif ($latency < 1500) $score += 10;
// 3. 搜尋引擎收錄量 (site:domain) - 需爬蟲或搜尋 API
// 4. 反向連結數 - 需第三方 API 或自建爬蟲
// 5. 社群分享數 - Facebook Graph API、Twitter API
return min(100, $score); // 0-100 分制
}
整合建議
- 內部管理後台:接入 DataForSEO 或 SimilarWeb API,定時同步關鍵指標。
- 公開展示頁面:使用自建評分 + 緩存 24 小時,避免即時查詢延遲。
- 歷史趨勢:將每日快照存入資料庫,繪製排名/流量走勢圖。
程式碼遷移檢查清單
- 移除所有
data.alexa.com 請求代碼。
- 替換為新 API 客戶端 (如
dataforseo-php-client)。
- 更新資料庫結構:新增
source 欄位標記數據來源。
- 調整前端顯示邏輯:標註「預估流量」而非「Alexa 排名」。
- 文檔說明:告知用戶 Alexa 已停止服務,數據來源已變更。
隨著 Alexa 退場,轉向多源數據融合的綜合 SEO 儀表板,是更穩健的長期策略。
copyright ©
萬盛學電腦網 all rights reserved