"""
@author : v_jiaohaicheng@baidu.com
@des : 开发者搜索接口
"""
import requests
def get_result(search_info):
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36",
}
url = "https://kaifa.baidu.com/rest/v1/search"
params = {
"wd": search_info,
"pageNum": "1",
}
response = requests.get(url, headers=headers, params=params)
if response.json()["status"] == "OK":
result_list = response.json()["data"]["documents"]["data"]
for id,args in enumerate(result_list):
url = args["techDocDigest"]["url"]
title = args["techDocDigest"]["realTitle"]
yield (id,url,title)
search_info = "python 音频音色矫正"
for id,url,title in get_result(search_info):
print(id,url,title)
"""
@author : v_jiaohaicheng@baidu.com
@des : 文心百中搜索接口
"""
import requests
def get_data(search_info):
headers = {
"Referer": "https://wenxin.baidu.com/baizhong/knowledgesearch/",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36",
}
cookies = {
"BDUSS_BFESS": "I3ZVJPSjRWSGNQRG5zUldoSmRVSVB3M3NTamg1bEtBTkR0bUI4QTM1Q2dsUTFrRVFBQUFBJCQAAAAAAAAAAAEAAAAQdrtY0fS54rXE37nfud-537kAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKAI5mOgCOZjY1",
}
url = "https://wenxin.baidu.com/baizhong/demo-api/demo-collection/search"
params = {
"q": search_info,
}
response = requests.get(url, headers=headers, cookies=cookies, params=params)
data = response.json()
if data["errCode"] == 0:
hits_list = data["baizhong"]["hits"]
for args in hits_list:
id = args["_id"]
title = args["_source"]["title"]
para = args["_source"]["para"]
doc = args["_source"]["doc"]
yield "百中", id,title,para,doc
keyword_engine_list = data["keyword_engine"]["hits"]
for args in keyword_engine_list:
id = args["_id"]
title = args["_source"]["title"]
para = args["_source"]["para"]
doc = args["_source"]["doc"]
yield "常规",id,title,para,doc
if __name__ == '__main__':
search_info = "二杆子"
for kind,id,title,para,doc in get_data(search_info):
print(kind,id,title,para,doc)```