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)
相关推荐
wuyk5552 天前
Spider-第16讲-线程池与竞态问题
大数据·爬虫·python·elasticsearch·搜索引擎
wuyk5556 天前
Spider-第11讲-工程化改造与可维护性
大数据·爬虫·elasticsearch·搜索引擎
wuyk5556 天前
Spider-第12讲-asyncio异步并发爬取
大数据·爬虫·elasticsearch·搜索引擎
dozenyaoyida6 天前
AI与大模型新闻日报 | 2026-11-08
人工智能·搜索引擎·ai·大模型·新闻
喵个咪10 天前
GoWind CMS 拆解:搜索三板斧——高亮、联想、同义词
后端·搜索引擎·go
Elastic 中国社区官方博客11 天前
更少的位数,相同的召回率:DiskBBQ 更保守的自动校准扫描
大数据·运维·开发语言·人工智能·elasticsearch·搜索引擎
翊众建站17 天前
用 JSON-LD 给企业官网做结构化数据:LocalBusiness 与 FAQPage 实践笔记
人工智能·搜索引擎·json
fengye20716117 天前
第三章 编译cpython
大数据·elasticsearch·搜索引擎
Elastic 中国社区官方博客18 天前
AgentHack Shanghai|基于阿里云AI搜索 Elasticsearch x Qoder 构建AI Agent应用
大数据·人工智能·elasticsearch·搜索引擎·阿里云·云计算·全文检索
真上帝的左手18 天前
30. 技术专题-‌应用框架组件-搜索引擎-ES
大数据·分布式·elasticsearch·搜索引擎·中间件