我已经使用Bing Search API 7天试用版(来宾)来获取基于术语的搜索结果。
我使用的是与https://docs.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个结果,而我收到的电子邮件为
您正在接近订阅Bing的配额限制SearchV7-免费产品。该配额将在2020年4月9日更新。
下面是有关订阅配额使用的详细信息:
配额范围 呼叫 呼叫配额 带宽 带宽配额
订阅2.26k 3.00k 58.48MB
我最多可以进行API调用多少次?如何限制仅对网页和每个域仅一页的搜索(即,我仅需要获取索引页面。我只需要基于搜索的域,因此无需在结果中再次获取相同的域页面)?
谁能帮我。
任何帮助将不胜感激。