diff --git a/searx/engines/bing.py b/searx/engines/bing.py index 171606cf6..6bdfd378b 100644 --- a/searx/engines/bing.py +++ b/searx/engines/bing.py @@ -54,6 +54,12 @@ def response(resp): dom = html.fromstring(resp.text) + try: + results.append({'number_of_results': int(dom.xpath('//span[@class="sb_count"]/text()')[0] + .split()[0].replace(',', ''))}) + except: + pass + # parse results for result in dom.xpath('//div[@class="sa_cc"]'): link = result.xpath('.//h3/a')[0] @@ -66,10 +72,6 @@ def response(resp): 'title': title, 'content': content}) - # return results if something is found - if results: - return results - # parse results again if nothing is found yet for result in dom.xpath('//li[@class="b_algo"]'): link = result.xpath('.//h2/a')[0] diff --git a/searx/engines/yahoo.py b/searx/engines/yahoo.py index 769e7e47f..b8b40e4aa 100644 --- a/searx/engines/yahoo.py +++ b/searx/engines/yahoo.py @@ -77,6 +77,13 @@ def response(resp): dom = html.fromstring(resp.text) + try: + results_num = int(dom.xpath('//div[@class="compPagination"]/span[last()]/text()')[0] + .split()[0].replace(',', '')) + results.append({'number_of_results': results_num}) + except: + pass + # parse results for result in dom.xpath(results_xpath): try: diff --git a/searx/results.py b/searx/results.py index c3040b305..dcd966ef7 100644 --- a/searx/results.py +++ b/searx/results.py @@ -99,6 +99,7 @@ class ResultContainer(object): self._infobox_ids = {} self.suggestions = set() self.answers = set() + self.number_of_results = 0 def extend(self, engine_name, results): for result in list(results): @@ -111,6 +112,9 @@ class ResultContainer(object): elif 'infobox' in result: self._merge_infobox(result) results.remove(result) + elif 'number_of_results' in result: + self.number_of_results = max(self.number_of_results, result['number_of_results']) + results.remove(result) with RLock(): engines[engine_name].stats['search_count'] += 1 diff --git a/searx/templates/oscar/results.html b/searx/templates/oscar/results.html index 9f9bdf1e1..db9eb96dd 100644 --- a/searx/templates/oscar/results.html +++ b/searx/templates/oscar/results.html @@ -78,6 +78,16 @@