Bing Custom Search returns too few results

Douwe Osinga 5 Reputation points
2023-07-28T16:04:15.46+00:00

I'm running fairly standard code:

def bing_search(num_results=50):
    headers = {"Ocp-Apim-Subscription-Key" : BING_KEY}
    response = requests.get("https://api.bing.microsoft.com/v7.0/search?q=microsoft+devices&count=" + str(num_results),
                            headers=headers)
    response.raise_for_status()
    search_text = response.text
    search_results = json.loads(search_text)

    return search_results['webPages']['value']

But if I pass in 50 as requested results, I get 23 results back, if I pass in 10, I get 9 results back.

Bing Custom Search
Bing Custom Search
An easy-to-use, ad-free, commercial-grade search tool that lets you deliver the results you want.
91 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. YutongTie-MSFT 53,211 Reputation points
    2023-07-29T19:30:45.2066667+00:00

    Hello @Douwe Osinga

    Thanks for reaching out to us, you need to set the value along with your offset parameter.

    As the document describes -

    Count is the number of search results to return in the response. The default is 10 and the maximum value that you may specify is 50. The actual number delivered may be less than requested.

    Use this parameter along with the offset parameter to page results. For more information, see Paging Webpages.
    **
    For example, if your user interface presents 10 search results per page, you would set count to 10 and offset to 0 to get the first page of results. For each subsequent page, you would increment offset by 10 (for example, 0, 10, 20). It is possible for multiple pages to include some overlap in results.**

    Please refer to the API reference for more information - https://learn.microsoft.com/en-us/rest/api/cognitiveservices-bingsearch/bing-custom-search-api-v7-reference#query-parameters

    I hope this helps! Please let me know if you have more questions.

    Regards,

    Yutong

    -Please kindly accept the answer and vote 'Yes' if you feel helpful to support the community, thanks a lot.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.