From 0001a7a57d9f9a5d3e7e0925e0b38642593240b4 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sun, 20 Jan 2019 18:01:56 +0100 Subject: Fix crash when parsing plein text result --- src/khaganatWikhan.py | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/khaganatWikhan.py b/src/khaganatWikhan.py index 083696c..988ee5a 100644 --- a/src/khaganatWikhan.py +++ b/src/khaganatWikhan.py @@ -43,26 +43,22 @@ def response(resp): doc = fromstring(resp.text) - # parse results - # Quickhits + # Page result for r in doc.xpath('//div[@class="search_quickresult"]/ul/li'): try: res_url = r.xpath('.//a[@class="wikilink1"]/@href')[-1] - except: - continue - - if not res_url: - continue + title = extract_text(r.xpath('.//a[@class="wikilink1"]/@title')) - title = extract_text(r.xpath('.//a[@class="wikilink1"]/@title')) + # append result + results.append({'title': title, + 'content': "Page "+title, + 'url': base_url + res_url}) - # append result - results.append({'title': title, - 'content': "", - 'url': base_url + res_url}) + except: + continue - # Search results - for r in doc.xpath('//dl[@class="search_results"]/*'): + # Plein text results + for r in doc.xpath('//div[@class="search_fullpage_result"]/*'): try: if r.tag == "dt": res_url = r.xpath('.//a[@class="wikilink1"]/@href')[-1] @@ -77,8 +73,5 @@ def response(resp): except: continue - if not res_url: - continue - # return results return results -- cgit v1.2.1