How to get number of search result from Bing API

2019-06-17 18:19发布

I want to use bing search api to obtain search result count for given query, however, Bing API seem to not return any fields containing the search result count.

Should I specify some option to request URL? Or Bing API not return the result countt?

标签: bing-api
3条回答
三岁会撩人
2楼-- · 2019-06-17 18:34

You can obtain the result count, but it's not as obvious as I thought it would be. Using this URL:

https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1/Composite?Sources=%27web%27&Query=%27YOUR_QUERY_HERE%27&$top=1&$format=JSON

you can get a JSON String, which includes the result count in

d->results[0]->WebTotal

You need to use the Composite search for that (I specified only web in this example, but you can use web+news or any other bing source) and you have to retrieve at least one result ($top=1).

You can also use Atom instead of JSON to get an xml response.

查看更多
Juvenile、少年°
3楼-- · 2019-06-17 18:45

For those subscribed to the SearchWeb stream rather than the general Search, the URL is this:

https://api.datamarket.azure.com/Data.ashx/Bing/SearchWeb/v1/Composite?Query=%27YOUR_QUERY_HERE%27&$top=1&$format=JSON

As with Wang Tang's answer, the result should include

d->results[0]->WebTotal
查看更多
疯言疯语
4楼-- · 2019-06-17 18:48

You can get the results count from the result object:

results_object['searchResults']['webPages']['totalEstimatedMatches']
查看更多
登录 后发表回答