bing官方api搜索引擎

bing官方api搜索引擎

1. bing API说明

微软 Bing 的搜索 API 使得开发者能够将 Bing 的搜索能力集成到自己的应用中,包括对网页、图片、新闻、视频的搜索,以及提供了实体搜索和视觉搜索的功能。这些 API 支持安全、无广告且能够根据地理位置提供相关信息的搜索结果。Bing Web Search API v7 允许用户从全球范围内的数十亿个网页文档中检索信息。

2. 秘钥申请

参考Langchain-Chatchat3.1------搜索引擎bing与DuckDuckGo

3. 官方文档地址

官方文档

4. coding案例

下面是一个bing的新闻搜索按理,采用fastapi进行快速部署的服务

复制代码
# -*- coding: utf-8 -*-
from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
import json
from datetime import datetime
import requests
import re



app = FastAPI()  # 创建API实例
app.add_middleware(
    CORSMiddleware,
    # 允许跨域的源列表,例如 ["http://www.example.org"] 等等,["*"] 表示允许任何源
    allow_origins=["*"],
    # 跨域请求是否支持 cookie,默认是 False,如果为 True,allow_origins 必须为具体的源,不可以是 ["*"]
    allow_credentials=False,
    # 允许跨域请求的 HTTP 方法列表,默认是 ["GET"]
    allow_methods=["*"],
    # 允许跨域请求的 HTTP 请求头列表,默认是 [],可以使用 ["*"] 表示允许所有的请求头
    # 当然 Accept、Accept-Language、Content-Language 以及 Content-Type 总之被允许的
    allow_headers=["*"],
    # 可以被浏览器访问的响应头, 默认是 [],一般很少指定
    # expose_headers=["*"]
    # 设定浏览器缓存 CORS 响应的最长时间,单位是秒。默认为 600,一般也很少指定
    # max_age=1000
)

def bing_news_search(search_term):

    subscription_key = "bing秘钥"

    search_url = "https://api.bing.microsoft.com/v7.0/news/search"
    headers = {"Ocp-Apim-Subscription-Key" : subscription_key}
    params  = {"q": search_term, "textDecorations": True, "textFormat": "HTML"}

    response = requests.get(search_url, headers=headers, params=params)
    status_code = response.status_code

    response.raise_for_status()
    search_results = response.json()
    return status_code,search_results["value"][0]


@app.post("/news_search")
async def create_item(request: Request):
    json_post_raw = await request.json()
    json_post = json.dumps(json_post_raw)
    json_post_list = json.loads(json_post)
    prompt = json_post_list.get('search')
    status_code,res = bing_news_search(prompt)

    now = datetime.now()
    time = now.strftime("%Y-%m-%d %H:%M:%S")

    answer = {
        "data": res,
        "status": status_code,
        "time": time
    }
    return answer


if __name__ == '__main__':
    uvicorn.run(app, host='0.0.0.0', port=9009, workers=1)
相关推荐
骑士雄师2 小时前
rag的具体案例:通过es在意图识别的时候进行个命中。
大数据·elasticsearch·搜索引擎
ly768919 小时前
Elasticsearch 分片分配与再平衡的底层逻辑:从 allocation decider 到集群扩容抖动
大数据·elasticsearch·搜索引擎·集群扩容·分片分配·磁盘水位线
Cx330❀1 天前
Qt 多线程深度解析:从底层原理到 UI 线程与同步实战
开发语言·qt·ui·搜索引擎·性能优化·图形渲染
ly76891 天前
Elasticsearch 写入链路的 refresh、flush 与 translog 边界:为什么 bulk 吞吐会突然塌陷
大数据·elasticsearch·搜索引擎·translog·写入链路·bulk调优
LaughingZhu1 天前
Product Hunt 每日热榜 | 2026-10-07
人工智能·深度学习·神经网络·搜索引擎·百度
LaughingZhu2 天前
Product Hunt 每日热榜 | 2026-10-06
人工智能·深度学习·神经网络·搜索引擎·百度
Elastic 中国社区官方博客2 天前
使用 Lucene 搜索你的 Bean — 索引
java·大数据·数据库·elasticsearch·搜索引擎·全文检索·lucene
LaughingZhu2 天前
Product Hunt 每日热榜 | 2026-10-03
人工智能·深度学习·神经网络·搜索引擎·百度
LaughingZhu2 天前
Product Hunt 每日热榜 | 2026-10-02
数据库·人工智能·深度学习·神经网络·搜索引擎
独立开发者阿乐2 天前
什么是 GEO:让 AI 搜索引擎引用你内容的完整指南
人工智能·搜索引擎·ai搜索引擎·geo优化·ai爬虫·llms.txt·clarabbs