申請免費的必應搜索API
文章目錄
- 申請免費的必應搜索API
- 前言
- 一、原理
- 1.1 登錄
- 1.2 進入
- 1.3 獲取密鑰
- 1.4 申請VISA信用卡
- 1.5 創建必應自定義搜索資源
- 二、創建成功
前言
準備條件:
1、outlook郵箱
2、招商銀行全幣種VISA信用卡【建議之前就有一張招商銀行信用卡,那么VISA相對比較好申請】
一、原理
1.1 登錄
https://www.customsearch.ai/
使用outlook郵箱登錄 sign in
1.2 進入
創建一個new instance
配置需要訪問的URL
這里輸入 https://cn.bing.com/
1.3 獲取密鑰
1.4 申請VISA信用卡
填寫信用卡的相關信息,實測招商銀行的全幣種VISA可以通過
1.5 創建必應自定義搜索資源
這里的資源組、名稱自定義填寫;定價層看實際需求填寫,最后審閱并創建
二、創建成功
本頁有測試,市場是選擇不同的地域,中國是zh-CN, 香港省是zh-HK
以下是python的示例代碼
#Copyright (c) Microsoft Corporation. All rights reserved.
#Licensed under the MIT License.# -*- coding: utf-8 -*-import json
import os
from pprint import pprint
import requests'''
This sample makes a call to the Bing Web Search API with a query and returns relevant web search.
Documentation: https://docs.microsoft.com/en-us/bing/search-apis/bing-web-search/overview
'''# Add your Bing Search V7 subscription key and endpoint to your environment variables.
subscription_key = os.environ['BING_SEARCH_V7_SUBSCRIPTION_KEY']
endpoint = os.environ['BING_SEARCH_V7_ENDPOINT'] + "/bing/v7.0/search"# Query term(s) to search for.
query = "Microsoft"# Construct a request
mkt = 'en-US'
params = { 'q': query, 'mkt': mkt }
headers = { 'Ocp-Apim-Subscription-Key': subscription_key }# Call the API
try:response = requests.get(endpoint, headers=headers, params=params)response.raise_for_status()print("
Headers:
")print(response.headers)print("
JSON Response:
")pprint(response.json())
except Exception as ex:raise ex