summaryrefslogtreecommitdiff
path: root/searx
diff options
context:
space:
mode:
authorasciimoo <asciimoo@gmail.com>2013-10-17 00:27:25 +0200
committerasciimoo <asciimoo@gmail.com>2013-10-17 00:27:25 +0200
commite467a24843b62ff444b20e81a7b22b0cc5783a9e (patch)
tree2052ce50bc14097e07c6b7190b694d301b7d8f3e /searx
parenta0037313ea1a3810aea50c6597c8a36eaebdd259 (diff)
downloadsearxng-e467a24843b62ff444b20e81a7b22b0cc5783a9e.tar.gz
searxng-e467a24843b62ff444b20e81a7b22b0cc5783a9e.zip
[enh] stackoverflow added
Diffstat (limited to 'searx')
-rw-r--r--searx/engines/stackoverflow.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/searx/engines/stackoverflow.py b/searx/engines/stackoverflow.py
new file mode 100644
index 000000000..fb0d65cdf
--- /dev/null
+++ b/searx/engines/stackoverflow.py
@@ -0,0 +1,25 @@
+from urllib import quote
+from lxml import html
+from urlparse import urljoin
+
+base_url = 'http://stackoverflow.com/'
+search_url = base_url+'search?q='
+
+def request(query, params):
+ global search_url
+ query = quote(query.replace(' ', '+'), safe='+')
+ params['url'] = search_url + query
+ return params
+
+
+def response(resp):
+ global base_url
+ results = []
+ dom = html.fromstring(resp.text)
+ for result in dom.xpath('//div[@class="question-summary search-result"]'):
+ link = result.xpath('.//div[@class="result-link"]//a')[0]
+ url = urljoin(base_url, link.attrib.get('href'))
+ title = ' '.join(link.xpath('.//text()'))
+ content = ' '.join(result.xpath('.//div[@class="excerpt"]//text()'))
+ results.append({'url': url, 'title': title, 'content': content})
+ return results