gpt4 book ai didi

php - Bing 搜索 API 限制并限制为每个域单个页面

转载 作者:行者123 更新时间:2023-12-03 04:42:37 27 4
gpt4 key购买 nike

我已使用 Bing Search API 7 天试用版(访客)来根据术语获取搜索结果。

我使用的代码与 https://learn.microsoft.com/en-us/azure/cognitive-services/bing-web-search/quickstarts/php 中指定的代码相同文档。我添加了一个 foreach 循环,以便可以获得每个页面的搜索结果。对于我的搜索词,我得到的 API 搜索结果计数 totalEstimatedMatches 为 38500000。

下面是我的代码:

function BingWebSearch ($url, $key, $query, $count="", $offset="") {
$headers = "Ocp-Apim-Subscription-Key: $key\r\n";
$options = array ('http' => array (
'header' => $headers,
'method' => 'GET'));

// Perform the request and get a JSON response.
$context = stream_context_create($options);
$queryString = "?q=" . urlencode($query);
if ( strlen(trim($count)) > 0 ) $queryString .= "&count=".$count;
if ( strlen(trim($offset)) > 0 ) $queryString .= "&offset=".$offset;
$result = file_get_contents($url . $queryString , false, $context);

// Extract Bing HTTP headers.
$headers = array();
foreach ($http_response_header as $k => $v) {
$h = explode(":", $v, 2);
if (isset($h[1]))
if (preg_match("/^BingAPIs-/", $h[0]) || preg_match("/^X-MSEdge-/", $h[0]))
$headers[trim($h[0])] = trim($h[1]);
}
return array($headers, $result);
}

$accessKey = 'xxxxxxxxxxxxxxxx';
$endpoint = 'https://api.cognitive.microsoft.com/bing/v7.0/search';
$term = 'myserchterm';

$searchOffset = 0;
$offset = 0;
$totalEstimatedMatchesCount = 38500000;
$count = 5000;
for ( $searchCount=0; $searchCount <= $totalEstimatedMatchesCount; $searchCount = $searchCount+$searchOffset ) {
$offset = $offset+$searchOffset;
list($headers, $jsonPageResult) = BingWebSearch($endpoint, $accessKey, $term, $count, $offset);
$bingSearchPageArray = json_decode($jsonPageResult);
$searchOffset = count($bingSearchPageArray['webPages']['value']);
// code to store result to database
.....................................
}

此代码仅给出 930 结果,我收到的电子邮件为

You are approaching the quota limit on you subscription to the BingSearchV7 - Free product. This quota will be renewed on 04/09/2020.

Below are details on quota usage for the subscription:

Quota Scope Calls Call Quota Bandwidth Bandwidth Quota

Subscription 2.26k 3.00k 58.48MB

我最多可以进行多少次 API 调用?如何限制搜索仅针对网页,并且每个域仅搜索一页(即,我只需要获取索引页。我只需要基于搜索的域,因此不需要在结果中再次获取相同的域页面)?

谁能帮帮我。

如有任何帮助,我们将不胜感激。

最佳答案

Bing 搜索 v7 API 订阅涵盖多项 Bing 搜索服务(Bing 图像搜索、Bing 新闻搜索、Bing 视频搜索、Bing 视觉搜索和 Bing 网页搜索),此定价页面解释了免费限制:https://azure.microsoft.com/en-us/pricing/details/cognitive-services/search-api/

您可以使用请求过滤器按主题(网页、图像、视频、新闻等)过滤搜索:https://learn.microsoft.com/en-us/azure/cognitive-services/bing-web-search/filter-answers

要将搜索限制为仅索引页,请尝试一些可以添加到查询中的高级搜索前缀:https://help.bing.microsoft.com/#apex/18/en-US/10001/-1

关于php - Bing 搜索 API 限制并限制为每个域单个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60634454/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com