diff options
| author | Adam Tauber <asciimoo@gmail.com> | 2015-01-01 14:10:59 +0100 |
|---|---|---|
| committer | Adam Tauber <asciimoo@gmail.com> | 2015-01-01 14:10:59 +0100 |
| commit | 469e08881ee17d8a180d0c0741c1552a29108f0e (patch) | |
| tree | 59db47065d54fdde5576babc19155f128359386f /searx/engines/digg.py | |
| parent | c7cbd38fcc60601dd3b41df8a3a234c079f5dc0b (diff) | |
| parent | 5d977056f7aa216eae09a22c3baaff73546f6ff1 (diff) | |
Merge pull request #165 from Cqoicebordel/Moar-engines
Moar engines
Diffstat (limited to 'searx/engines/digg.py')
| -rw-r--r-- | searx/engines/digg.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/searx/engines/digg.py b/searx/engines/digg.py new file mode 100644 index 000000000..241234fdb --- /dev/null +++ b/searx/engines/digg.py @@ -0,0 +1,67 @@ +## Digg (News, Social media) +# +# @website https://digg.com/ +# @provide-api no +# +# @using-api no +# @results HTML (using search portal) +# @stable no (HTML can change) +# @parse url, title, content, publishedDate, thumbnail + +from urllib import quote_plus +from json import loads +from lxml import html +from cgi import escape +from dateutil import parser + +# engine dependent config +categories = ['news', 'social media'] +paging = True + +# search-url +base_url = 'https://digg.com/' +search_url = base_url+'api/search/{query}.json?position={position}&format=html' + +# specific xpath variables +results_xpath = '//article' +link_xpath = './/small[@class="time"]//a' +title_xpath = './/h2//a//text()' +content_xpath = './/p//text()' +pubdate_xpath = './/time' + + +# do search-request +def request(query, params): + offset = (params['pageno'] - 1) * 10 + params['url'] = search_url.format(position=offset, + query=quote_plus(query)) + return params + + +# get response from search-request +def response(resp): + results = [] + + search_result = loads(resp.text) + + dom = html.fromstring(search_result['html']) + + # parse results + for result in dom.xpath(results_xpath): + url = result.attrib.get('data-contenturl') + thumbnail = result.xpath('.//img')[0].attrib.get('src') + title = ''.join(result.xpath(title_xpath)) + content = escape(''.join(result.xpath(content_xpath))) + pubdate = result.xpath(pubdate_xpath)[0].attrib.get('datetime') + publishedDate = parser.parse(pubdate) + + # append result + results.append({'url': url, + 'title': title, + 'content': content, + 'template': 'videos.html', + 'publishedDate': publishedDate, + 'thumbnail': thumbnail}) + + # return results + return results |