根据网站地址/域名查询其竞价关键词等数据
query 参数说明:
本参数可以取值域名(例如baidu.com)或子域名(例如wenku.baidu.com)
一级域名查询出的数据可能比二级域名多(例如:查询条件为baidu.com时会查询其所有子域名的数据,其中包括wenku.baidu.com,*.baidu.com等)
计费规则:一次调用计费一次
参数 | 类型 | 描述 | 是否必填 |
---|---|---|---|
app_id | string | 接口AppId(本接口AppId为: 10002 ) | 是 |
access_key | string | 获取方式:用户中心->Api数据->接口管理 | 是 |
access_token | string | 计算方式请参照本页面《AccessToken计算规则》说明 | 是 |
query | string | 查询地址(例如:wenku.baidu.com,不要带有http或https等协议信息) | 是 |
page | int | 分页(不传默认为1,最大50) | 否 |
sort_field | string | 排序字段(仅支持int类型字段) | 否 |
sort_direction | string | 排序方向(正序:asc;倒序:desc) | 否 |
参数 | 类型 | 描述 |
---|---|---|
word | string | 关键词 |
title | string | 网页标题 |
domain | string | 域名 |
host | string | host地址 |
company_name | string | 机构名称 |
index_pc | int | 指数(PC) |
index_mobile | int | 指数(移动) |
pv_pc | int | 检索量(PC) |
pv_mobile | int | 检索量(移动) |
bid_price | float | 竞价参考价格 |
complexity | int | 竞价复杂程度(值越大越难) |
{
"code": 1,
"data": {
"result": [
{
"bid_price": "0.00",
"company_name": "百度文库",
"complexity": 0,
"domain": "baidu.com",
"host": "wenku.baidu.com",
"index_mobile": 0,
"index_pc": 0,
"landing_page": "http://wenku.baidu.com/tfview/xxxxxxxxx.html",
"pv_mobile": 0,
"pv_pc": 0,
"title": "2022文库文档下载,即下即用,最新文档,千万热门收录",
"word": "文库文档下载"
},
{
"bid_price": "0.00",
"company_name": "百度文库",
"complexity": 0,
"domain": "baidu.com",
"host": "wenku.baidu.com",
"index_mobile": 0,
"index_pc": 0,
"landing_page": "https://wenku.baidu.com/tfview/xxxxxxxx.html",
"pv_mobile": 0,
"pv_pc": 0,
"title": "2022中考满分作文100篇文档下载,即下即用, [完整版] .doc",
"word": "突破作文"
},
......
],
"total": 188634
},
"message": "success"
}
错误码 | 返回消息 | 错误说明 |
---|---|---|
-4000 | app_id can not be empty | app_id参数为空 |
-4001 | access_key can not be empty | access_key参数为空 |
-4002 | access_token can not be empty | access_token参数为空 |
-4003 | access key is invalid | access_key可能错误或被禁用 |
-4004 | access token is invalid | access token错误,access_token计算规则请查看本页面帮助 |
-3001 | no valid count | 接口可用次数不足 |
错误码 | 错误消息 | 备注 |
---|---|---|
0 | param "app_id" error | app_id参数错误 |
-1 | error params | 参数错误 |
-2 | page size exceed limit | 单页数目范围超出限制(单页最大100条) |
-3 | page number exceed limit | 页码范围超出限制(最大100页) |
-4 | sort field error/error params | 排序参数(sort_field或sort_direction)错误 |
<?php
class Cichacha
{
public function index()
{
$appId = 10000; //对应接口应用ID,此处以关键词挖掘接口为例
$accessKey = "369c4754d0bd*********"; //用户中心-密钥管理获取
$secretKey = "SSHGxwtRNb**************";//用户中心-密钥管理获取
$apiUrl = "https://openapi.cichacha.com/....."; //接口地址
$accessToken = md5($appId . $accessKey . md5($secretKey));
$params = [ //必备参数
"app_id" => $appId,
"access_key" => $accessKey,
"access_token" => $accessToken,
];
$paramsApi = [ // 接口应用相关参数
"word" => "seo" // 根据接口应用参数来增删,此处以关键词挖掘接口为例
];
$res = $this->httpRequest($apiUrl, array_merge($params, $paramsApi));
echo $res;
}
/**
* HTTP请求
* @param $url
* @param array $data
* @param false $isPost 是否是POST请求
* @return bool|string
*/
private function httpRequest($url, array $data = [], bool $isPost = false)
{
$ch = curl_init();
if ($isPost == false) {
$url = $url . "?" . http_build_query($data);
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
if ($isPost) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
}
?>
# -*- coding: utf-8 -*-
import hashlib
from requests import get
def md5_hex(s):
return hashlib.md5(s.encode("utf-8")).hexdigest()
if __name__ == "__main__":
appId = 10000 # 对应接口应用ID, 此处以关键词挖掘接口为例
accessKey = "369c4754d0bd*********" # 用户中心 - 密钥管理获取
secretKey = "SSHGxwtRNb**************" # 用户中心 - 密钥管理获取
apiUrl = "https://openapi.cichacha.com/....." # 接口地址
accessToken = md5_hex(str(appId) + accessKey + md5_hex(secretKey))
# 必要参数
params = {
"app_id": appId,
"access_key": accessKey,
"access_token": accessToken,
}
# 接口参数,本示例以关键词挖掘API为例
paramsApi = {
"word": "qq",
"page": 1
}
params.update(paramsApi)
res = get(apiUrl, params=params).json()
print(res)
package main
import (
"crypto/md5"
"encoding/hex"
"fmt"
"io/ioutil"
"net/http"
)
func Md5(str string) string {
m := md5.New()
m.Write([]byte(str))
return hex.EncodeToString(m.Sum(nil))
}
func main() {
appId := "10000" //对应接口应用ID,此处以关键词挖掘接口为例
accessKey := "369c47***************" //用户中心-密钥管理获取
secretKey := "SSHGxwt***************" //用户中心-密钥管理获取
accessToken := Md5(fmt.Sprintf("%s%s%s", appId, accessKey, Md5(secretKey)))
// 必备参数
baseQueryString := fmt.Sprintf("app_id=%s&access_key=%s&access_token=%s&", appId, accessKey, accessToken)
// 本处接口地址和参数以关键词挖掘接口为例
apiUrl := fmt.Sprintf("https://openapi.cichacha.com/ciku/?%sword=%s&page=1", baseQueryString, "seo")
client := &http.Client{}
req, err := http.NewRequest("GET", apiUrl, nil)
if err != nil {
fmt.Println(err)
return
}
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}