Php Bing搜索API限制并限制为每个域一页

Php Bing搜索API限制并限制为每个域一页,php,azure,search,microsoft-cognitive,bing-api,Php,Azure,Search,Microsoft Cognitive,Bing Api,我已经使用Bing搜索API 7天试用版(Guest)来获取基于某个术语的搜索结果 我使用的代码与文档中指定的代码相同。 我添加了一个foreach循环,这样我就可以得到每个页面的搜索结果。对于我的搜索词,API搜索结果计数totalEstimatedMatches为38500000 下面是我的代码: function BingWebSearch ($url, $key, $query, $count="", $offset="") { $head

我已经使用Bing搜索API 7天试用版(Guest)来获取基于某个术语的搜索结果

我使用的代码与文档中指定的代码相同。 我添加了一个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
        .....................................
}
函数BingWebSearch($url、$key、$query、$count=“”、$offset=“”){
$headers=“Ocp Apim订阅密钥:$Key\r\n”;
$options=array('http'=>array)(
'header'=>$headers,
'方法'=>'获取');
//执行请求并获得JSON响应。
$context=stream\u context\u create($options);
$queryString=“?q=“.urlencode($query);
如果(strlen(trim($count))>0)$queryString=“&count=”.$count;
如果(strlen(trim($offset))>0)$queryString=“&offset=”.$offset;
$result=file\u get\u contents($url.$queryString,false,$context);
//提取Bing HTTP头。
$headers=array();
foreach($http\u response\u头为$k=>$v){
$h=爆炸(“:”,$v,2);
如果(isset($h[1]))
if(preg_match(“/^bingapi-/”,$h[0])| | preg_match(“/^X-MSEdge-/”,$h[0]))
$headers[trim($h[0])]=trim($h[1]);
}
返回数组($headers,$result);
}
$accessKey='XXXXXXXXXXXXXX';
$endpoint=https://api.cognitive.microsoft.com/bing/v7.0/search';
$term='myserchterm';
$searchOffset=0;
$offset=0;
$TotalEstimatedMatchescont=38500000;
$count=5000;

对于($searchCount=0;$searchCountBing Search v7 API订阅涵盖多个Bing搜索服务(Bing图像搜索、Bing新闻搜索、Bing视频搜索、Bing视觉搜索和Bing Web搜索),此定价页解释了免费限制:

您可以使用请求筛选器按主题(网页、图像、视频、新闻等)筛选搜索:

若要将搜索限制为仅索引页面,请尝试以下可添加到查询中的高级搜索前缀: