diff options
| author | asciimoo <asciimoo@gmail.com> | 2013-10-19 18:29:39 +0200 |
|---|---|---|
| committer | asciimoo <asciimoo@gmail.com> | 2013-10-19 18:29:39 +0200 |
| commit | 57eaeb9b74cd73d94863a6b8d4bbb7cd7e455197 (patch) | |
| tree | 46ed1b692b56b60a0df0562c31ae40d6d4b755c8 /searx/engines/startpage.py | |
| parent | e85972b5e1d296a7eca1eb0d27cdfcab7bdf9360 (diff) | |
[enh] startpage engine added
Diffstat (limited to 'searx/engines/startpage.py')
| -rw-r--r-- | searx/engines/startpage.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/searx/engines/startpage.py b/searx/engines/startpage.py new file mode 100644 index 000000000..bad5fa1c3 --- /dev/null +++ b/searx/engines/startpage.py @@ -0,0 +1,28 @@ +from urllib import quote +from lxml import html +from urlparse import urljoin +from cgi import escape + +base_url = 'http://startpage.com/' +search_url = base_url+'do/search' + +def request(query, params): + global search_url + query = quote(query.replace(' ', '+'), safe='+') + params['url'] = search_url + params['method'] = 'POST' + params['data'] = {'query': query} + return params + + +def response(resp): + global base_url + results = [] + dom = html.fromstring(resp.text) + for result in dom.xpath('//div[@class="result"]'): + link = result.xpath('.//h3/a')[0] + url = urljoin(base_url, link.attrib.get('href')) + title = ' '.join(link.xpath('.//text()')) + content = escape(' '.join(result.xpath('.//p[@class="desc"]//text()'))) + results.append({'url': url, 'title': title, 'content': content}) + return results |