on master help sign in
[enh] twitter engine added
commitc7b5cddc485768f47a75b2432a5aebd0130f676c authorasciimoo <asciimoo@gmail.com> dateSun 20 Oct 2013, 10:40 (13 years ago) parent0cfc4b4
1 file changed+26
searx/engines/twitter.py+26
searx/engines/twitter.pynew file+26
@@ -0,0 +1,26 @@
1+from urlparse import urljoin
2+from urllib import urlencode
3+from lxml import html
4+
5+categories = ['social media']
6+
7+base_url = 'https://twitter.com/'
8+search_url = base_url+'search?'
9+
10+def request(query, params):
11+ global search_url
12+ params['url'] = search_url + urlencode({'q': query})
13+ return params
14+
15+
16+def response(resp):
17+ global base_url
18+ results = []
19+ dom = html.fromstring(resp.text)
20+ for tweet in dom.xpath('//li[@data-item-type="tweet"]'):
21+ link = tweet.xpath('.//small[@class="time"]//a')[0]
22+ url = urljoin(base_url, link.attrib.get('href'))
23+ title = ''.join(tweet.xpath('.//span[@class="username js-action-profile-name"]//text()'))
24+ content = ''.join(map(html.tostring, tweet.xpath('.//p[@class="js-tweet-text tweet-text"]//*')))
25+ results.append({'url': url, 'title': title, 'content': content})
26+ return results