如何免費獲取 Walmart API?詳細指南與實現方案

Walmart API 提供了豐富的產品、訂單、價格和庫存數據,對於開發者來說是一個強大的工具。然而,官方 API 需要 Walmart Marketplace 商家身份才能獲取正式環境的訪問權限。那麼,如何免費獲取 Walmart API?

1. 申請官方 Walmart API

Walmart 提供了官方 API,但正式環境需要商家身份才可使用。不過,開發者仍可免費申請 Sandbox(沙盒)環境,進行 API 測試。

申請步驟

  1. 註冊 Walmart Marketplace 開發者帳戶

    • 進入 Walmart Developer Portal 並註冊帳戶。

  2. 獲取 API Key

    • 登錄開發者帳戶,進入 API Key Management,申請 Sandbox API Key(免費)。

  3. 使用 API 測試數據

    • Sandbox API 提供模擬數據,可用於開發和測試。

官方 API 調用示例

以下為 Python 透過 Sandbox API 獲取商品數據的示例:

import requests

headers = {

"WM_SVC.NAME": "Walmart Marketplace",

"WM_QOS.CORRELATION_ID": "your_correlation_id",

"Authorization": "Basic your_encoded_credentials",

"Accept": "application/json"

}

response = requests.get(

"https://sandbox.walmartapis.com/v3/items?limit=10",

headers=headers

)

print(response.json())

請替換 "your_encoded_credentials" 為你的 API 金鑰。

2. 使用 Walmart 其他免費數據源

如果不想註冊官方 API,仍然可以通過 Walmart 提供的 RSS 訂閱 獲取部分公開數據,如暢銷商品和新品資訊。

使用 Walmart RSS 獲取商品數據

Python 解析 Walmart RSS

import feedparser

url = "https://www.walmart.com/rss/browse/bestsellers"

feed = feedparser.parse(url)

for entry in feed.entries:

print(entry.title, entry.link)

這段程式碼將解析 Walmart 暢銷商品 RSS,輸出商品標題與對應鏈接。

3. 使用 Web Scraping 爬取 Walmart 數據

如果 API 訪問受限,另一種免費獲取 Walmart 數據的方法是使用 Web Scraping(網頁爬取)。不過,請務必遵守 Walmart 的 robots.txt 規範,避免過度請求影響網站運行。

Python 爬取 Walmart 商品數據

import requests

from bs4 import BeautifulSoup

url = "https://www.walmart.com/search?q=laptop"

headers = {"User-Agent": "Mozilla/5.0"}

response = requests.get(url, headers=headers)

soup = BeautifulSoup(response.text, "html.parser")

for item in soup.select(".search-result-gridview-item"):

title = item.select_one(".product-title").text.strip()

print(title)

這段程式碼將提取 Walmart 搜尋結果頁面上的產品名稱。

4. 使用 Luckdata Walmart API(無需官方身份驗證)

如果不想註冊 Walmart 開發者帳戶,也可以選擇使用 Luckdata 提供的 Walmart API,它不需要官方身份驗證,支持直接調用。

Luckdata API 簡介

Luckdata 的 Walmart API 允許開發者訪問 Walmart 產品數據,支持:

  • 商品搜尋

  • 詳細信息查詢

  • 評論數據獲取

Luckdata API 免費配額

  • 免費版:每月 100 積分,每秒 1 個請求

  • Basic 版:$87.0/月,58000 積分/月,每秒 5 個請求

  • Pro 版:$299.0/月,230000 積分/月,每秒 10 個請求

  • Ultra 版:$825.0/月,750000 積分/月,每秒 15 個請求

Luckdata API 調用示例

Python 調用 Luckdata Walmart API

import requests

headers = {

'X-Luckdata-Api-Key': 'your luckdata key'

}

response = requests.get(

'https://luckdata.io/api/walmart-API/get_vwzq?url=https://www.walmart.com/ip/439625664',

headers=headers

)

print(response.json())

Java 調用 Luckdata Walmart API

import java.io.IOException;

import java.net.URI;

import java.net.http.HttpClient;

import java.net.http.HttpRequest;

import java.net.http.HttpResponse;

HttpClient client = HttpClient.newHttpClient();

HttpRequest request = HttpRequest.newBuilder()

.uri(URI.create("https://luckdata.io/api/walmart-API/get_vwzq?url=https://www.walmart.com/ip/439625664"))

.GET()

.setHeader("X-Luckdata-Api-Key", "your luckdata key")

.build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

System.out.println(response.body());

Luckdata API 無需官方 Walmart 賬戶驗證,適合需要快速獲取數據的開發者。

5. 如何選擇適合你的方法?

方法

免費/付費

適用場景

官方 Walmart API

免費(沙盒環境)/ 付費(正式環境)

需商家身份,適用於 Marketplace 賣家

Walmart RSS 訂閱

免費

適用於獲取熱門商品、新品數據

Web Scraping

免費

適用於無 API 訪問權限的情況(需遵守 Walmart 規範)

Luckdata Walmart API

免費(有限請求)/ 付費(高請求量)

無需官方驗證,適用於開發者快速調用 API

如果你是 Walmart Marketplace 賣家,官方 API 是最佳選擇;如果僅需獲取部分商品數據,RSS 訂閱Luckdata API 可能是更方便的方案;而如果你無法獲取 API 訪問權限,則可以考慮 Web Scraping。選擇最適合你的方式,以最低的成本獲取所需數據!