47def response(resp):
48 results = []
49
50 doc = fromstring(resp.text)
51
52
53
54 for r in eval_xpath(doc, '//div[@class="search_quickresult"]/ul/li'):
55 try:
56 res_url = eval_xpath(r, './/a[@class="wikilink1"]/@href')[-1]
57 except:
58 continue
59
60 if not res_url:
61 continue
62
63 title = extract_text(eval_xpath(r, './/a[@class="wikilink1"]/@title'))
64
65
66 results.append({'title': title, 'content': "", 'url': base_url + res_url})
67
68
69 for r in eval_xpath(doc, '//dl[@class="search_results"]/*'):
70 try:
71 if r.tag == "dt":
72 res_url = eval_xpath(r, './/a[@class="wikilink1"]/@href')[-1]
73 title = extract_text(eval_xpath(r, './/a[@class="wikilink1"]/@title'))
74 elif r.tag == "dd":
75 content = extract_text(eval_xpath(r, '.'))
76
77
78 results.append({'title': title, 'content': content, 'url': base_url + res_url})
79 except:
80 continue
81
82 if not res_url:
83 continue
84
85
86 return results