diff options
author | pw3t <romain@berthor.fr> | 2014-01-06 22:15:46 +0100 |
---|---|---|
committer | pw3t <romain@berthor.fr> | 2014-01-06 22:15:46 +0100 |
commit | 1950e697d6bd6efe184e1f2db0ed71267a284682 (patch) | |
tree | 087f46f9c6f9e3831adb830d20b2aa8264628f45 /searx/engines/vimeo.py | |
parent | 68364df342e4ba09ca3faf95d938285ea646bd68 (diff) | |
download | searxng-1950e697d6bd6efe184e1f2db0ed71267a284682.tar.gz searxng-1950e697d6bd6efe184e1f2db0ed71267a284682.zip |
[enh] Improved vimeo search engines, and add the configuration in the sample
Diffstat (limited to 'searx/engines/vimeo.py')
-rw-r--r-- | searx/engines/vimeo.py | 48 |
1 files changed, 19 insertions, 29 deletions
diff --git a/searx/engines/vimeo.py b/searx/engines/vimeo.py index 3a6ac96e9..486c76d40 100644 --- a/searx/engines/vimeo.py +++ b/searx/engines/vimeo.py @@ -1,48 +1,38 @@ from urllib import urlencode from HTMLParser import HTMLParser -from xpath import * +from xpath import extract_text +from lxml import html -categories = ['dev'] - -search_url = 'http://vimeo.com/search?{query}' +base_url = 'http://vimeo.com' +search_url = base_url + '/search?{query}' +# the cookie set by vime contains all the following values, but only __utma seems to be requiered Cookie = { - 'vuid':'918282893.1027205400' - , 'ab_bs':'%7B%223%22%3A279%7D' - , '__utma':'18302654.101#6140782.1388942090.1388942090.1388942090.1' - , '__utmb':'18302654.1.10.1388942090' - , '__utmc':'18302654' - , '__utmz':'18#302654.1388942090.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)' - , '__utml':'search' + #'vuid':'918282893.1027205400' + # 'ab_bs':'%7B%223%22%3A279%7D' + '__utma':'00000000.000#0000000.0000000000.0000000000.0000000000.0' + # '__utmb':'18302654.1.10.1388942090' + #, '__utmc':'18302654' + #, '__utmz':'18#302654.1388942090.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)' + #, '__utml':'search' } -#'vuid=918282893.1027205400& ab_bs=%7B%223%22%3A279%7D& player="scaling=1&volume=1"& __utma=18302654.101#6140782.1388942090.1388942090.1388942090.1& __utmb=18302654.1.10.1388942090& __utmc=18302654& __utmz=18#302654.1388942090.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)& __utmli=search' - def request(query, params): params['url'] = search_url.format(query=urlencode({'q' :query})) print params['url'] params['cookies'] = Cookie return params - def response(resp): results = [] - dom = html.fromstring(resp.text) + + p = HTMLParser() - if results_xpath: - for result in dom.xpath(results_xpath): - url = extract_url(result.xpath(url_xpath)) - - title = extract_text(result.xpath(title_xpath)[0 ]) - content = extract_text(result.xpath(content_xpath)[0]) - results.append({'url': url, 'title': title, 'content': content}) - else: - for url, title, content in zip( - map(extract_url, dom.xpath(url_xpath)), \ - map(extract_text, dom.xpath(title_xpath)), \ - map(extract_text, dom.xpath(content_xpath)), \ - ): - results.append({'url': url, 'title': title, 'content': content}) + for result in dom.xpath(results_xpath): + url = base_url + result.xpath(url_xpath)[0] + title = p.unescape(extract_text(result.xpath(title_xpath))) + content = '<a href="{0}"> <img src="{2}"/> </a>'.format(url, title, extract_text(result.xpath(content_xpath)[0])) + results.append({'url': url, 'title': title, 'content': content}) return results |