diff options
author | Dalf <alex@al-f.net> | 2014-01-05 13:55:17 +0100 |
---|---|---|
committer | Dalf <alex@al-f.net> | 2014-01-05 13:55:17 +0100 |
commit | 49c85fce51c2b8431013d9269999eac5a6a9c038 (patch) | |
tree | 5ca4a97f0d5b9fe640b5c1e8e8140feecb98a546 /searx/engines/dailymotion.py | |
parent | e88cf0a0a877458e2babc8af43c5a77654036af6 (diff) | |
download | searxng-49c85fce51c2b8431013d9269999eac5a6a9c038.tar.gz searxng-49c85fce51c2b8431013d9269999eac5a6a9c038.zip |
[fix] dailymotion engine : no more html tag in the description
Diffstat (limited to 'searx/engines/dailymotion.py')
-rw-r--r-- | searx/engines/dailymotion.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/searx/engines/dailymotion.py b/searx/engines/dailymotion.py index 7046132f3..655485957 100644 --- a/searx/engines/dailymotion.py +++ b/searx/engines/dailymotion.py @@ -1,16 +1,17 @@ from urllib import urlencode +from lxml import html from json import loads from cgi import escape categories = ['videos'] -localization = 'en' +locale = 'en_US' # see http://www.dailymotion.com/doc/api/obj-video.html search_url = 'https://api.dailymotion.com/videos?fields=title,description,duration,url,thumbnail_360_url&sort=relevance&limit=25&page=1&{query}' def request(query, params): global search_url - params['url'] = search_url.format(query=urlencode({'search': query, 'localization': localization })) + params['url'] = search_url.format(query=urlencode({'search': query, 'localization': locale })) return params @@ -27,6 +28,11 @@ def response(resp): else: content = '' if res['description']: - content += escape(res['description'][:500]) + description = text_content_from_html(res['description']) + content += description[:500] results.append({'url': url, 'title': title, 'content': content}) return results + +def text_content_from_html(html_string): + desc_html = html.fragment_fromstring(html_string, create_parent=True) + return desc_html.text_content() |