|
@@ -0,0 +1,38 @@
|
|
1
|
+from urllib import urlencode
|
|
2
|
+from HTMLParser import HTMLParser
|
|
3
|
+from xpath import extract_text
|
|
4
|
+from lxml import html
|
|
5
|
+
|
|
6
|
+base_url = 'http://vimeo.com'
|
|
7
|
+search_url = base_url + '/search?{query}'
|
|
8
|
+
|
|
9
|
+# the cookie set by vime contains all the following values, but only __utma seems to be requiered
|
|
10
|
+Cookie = {
|
|
11
|
+ #'vuid':'918282893.1027205400'
|
|
12
|
+ # 'ab_bs':'%7B%223%22%3A279%7D'
|
|
13
|
+ '__utma':'00000000.000#0000000.0000000000.0000000000.0000000000.0'
|
|
14
|
+ # '__utmb':'18302654.1.10.1388942090'
|
|
15
|
+ #, '__utmc':'18302654'
|
|
16
|
+ #, '__utmz':'18#302654.1388942090.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)'
|
|
17
|
+ #, '__utml':'search'
|
|
18
|
+}
|
|
19
|
+
|
|
20
|
+def request(query, params):
|
|
21
|
+ params['url'] = search_url.format(query=urlencode({'q' :query}))
|
|
22
|
+ print params['url']
|
|
23
|
+ params['cookies'] = Cookie
|
|
24
|
+ return params
|
|
25
|
+
|
|
26
|
+def response(resp):
|
|
27
|
+ results = []
|
|
28
|
+ dom = html.fromstring(resp.text)
|
|
29
|
+
|
|
30
|
+ p = HTMLParser()
|
|
31
|
+
|
|
32
|
+ for result in dom.xpath(results_xpath):
|
|
33
|
+ url = base_url + result.xpath(url_xpath)[0]
|
|
34
|
+ title = p.unescape(extract_text(result.xpath(title_xpath)))
|
|
35
|
+ content = '<a href="{0}"> <img src="{2}"/> </a>'.format(url, title, extract_text(result.xpath(content_xpath)[0]))
|
|
36
|
+ results.append({'url': url, 'title': title, 'content': content})
|
|
37
|
+
|
|
38
|
+ return results
|