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)
相关推荐
静听松涛13314 小时前
中文PC端多人协作泳道图制作平台
大数据·论文阅读·人工智能·搜索引擎·架构·流程图·软件工程
hepingfly18 小时前
外链的两个指标,DR 和 UR 一次性讲清楚
搜索引擎·个人开发·seo
老陈头聊SEO20 小时前
生成引擎优化(GEO)在提升内容创作质量与用户体验中的重要作用与策略探讨
其他·搜索引擎·seo优化
lagrahhn21 小时前
scoop的使用
大数据·python·搜索引擎
LaughingZhu2 天前
Product Hunt 每日热榜 | 2026-01-09
人工智能·经验分享·神经网络·搜索引擎·产品运营
Cx330❀2 天前
Git 多人协作全攻略:从入门到高效协同
大数据·elasticsearch·搜索引擎·gitee·github·全文检索·gitcode
TOPGUS2 天前
谷歌Chrome浏览器即将对HTTP网站设卡:突出展示“始终使用安全连接”功能
前端·网络·chrome·http·搜索引擎·seo·数字营销
AC赳赳老秦2 天前
Unity游戏开发实战指南:核心逻辑与场景构建详解
开发语言·spring boot·爬虫·搜索引擎·全文检索·lucene·deepseek
Elastic 中国社区官方博客2 天前
在 ES|QL 中的混合搜索和多阶段检索
大数据·人工智能·sql·elasticsearch·搜索引擎·ai·全文检索
TOPGUS3 天前
黑帽GEO手法揭秘:AI搜索阴影下的新型搜索劫持与风险
人工智能·搜索引擎·chatgpt·aigc·谷歌·数字营销