How to get number of search result from Bing API
Asked Answered
D

3

7

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?

Dortch answered 26/11, 2012 at 7:34 Comment(0)
I
6

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.

Incautious answered 26/11, 2012 at 20:23 Comment(0)
G
4

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
Georgia answered 14/3, 2013 at 8:55 Comment(3)
Any idea how can I know the number of pages? Because the number of search results is not reliable. It is normally an estimation and the real results shown to you as much less. I need to know how many pages so I can traverse over them but I am unable to find any way. Let me know if you have any idea.Bar
@user2192774, any count of the number of pages would be an estimate based on total estimated results. However, the number of results should be updated as you request each page, so assuming you're requesting the pages in order, you should be able to tell when you've reached the last one.Georgia
The pages links that appear in the button of the web search page is actual. If there are 10pages, you can navigate them and you will find results in each pages. But the total no.of results from my own experience is always ways exaggerated.Bar
I
0

You can get the results count from the result object:

results_object['searchResults']['webPages']['totalEstimatedMatches']
Inenarrable answered 10/1, 2019 at 14:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.