浏览文档
/
SERPCHEAP / 开始使用
代码示例
复制 curl、Python 或 JavaScript 示例,在自己的服务端运行。
本页目录
curl
CURL
curl -X POST 'https://serpcheap.com/search' \
-H 'X-API-KEY: YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{"q":"Nike","gl":"us","hl":"en"}'Python
Python
import json, os, urllib.request
request = urllib.request.Request("https://serpcheap.com/search",
data=json.dumps({"q":"Nike", "gl":"us", "hl":"en"}).encode(),
headers={"X-API-KEY":os.environ["SERP_API_KEY"],
"Content-Type":"application/json"})
with urllib.request.urlopen(request, timeout=55) as response:
print(json.load(response))JavaScript
JavaScript
const response = await fetch("https://serpcheap.com/search", {
method: "POST",
headers: {"X-API-KEY":process.env.SERP_API_KEY,
"Content-Type":"application/json"},
body: JSON.stringify({q:"Nike", gl:"us", hl:"en"})
});
const result = await response.json();
if (!response.ok) throw new Error(result.error.code);
console.log(result);示例仅说明接口合同,不会执行搜索。联系支持时请勿提供 API Key。
