Better error message when Bing returns no results

This commit is contained in:
Kovid Goyal 2024-12-05 09:10:59 +05:30
parent a00d5d0ca2
commit b36c8d32c6
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -238,7 +238,10 @@ def resolve_bing_wrapper_page(url, br, log):
return m.group(1)
def bing_search(terms, site=None, br=None, log=prints, safe_search=False, dump_raw=None, timeout=60, show_user_agent=False, result_url_is_ok=lambda x: True):
def bing_search(
terms, site=None, br=None, log=prints, safe_search=False, dump_raw=None, timeout=60,
show_user_agent=False, result_url_is_ok=lambda x: True
):
# http://vlaurie.com/computers2/Articles/bing_advanced_search.htm
terms = [quote_term(bing_term(t)) for t in terms]
if site is not None:
@ -261,7 +264,11 @@ def bing_search(terms, site=None, br=None, log=prints, safe_search=False, dump_r
root = query(br, url, 'bing', dump_raw, timeout=timeout)
ans = []
for li in root.xpath('//*[@id="b_results"]/li[@class="b_algo"]'):
result_items = root.xpath('//*[@id="b_results"]/li[@class="b_algo"]')
if not result_items:
log('Bing returned no results')
return ans, url
for li in result_items:
a = li.xpath('descendant::h2/a[@href]') or li.xpath('descendant::div[@class="b_algoheader"]/a[@href]')
a = a[0]
title = tostring(a)