ソースを参照

[enh] removing result html tags

asciimoo 11 年 前
コミット
17bf00ee42
共有4 個のファイルを変更した7 個の追加6 個の削除を含む
  1. 2
    1
      searx/engines/duckduckgo.py
  2. 2
    2
      searx/engines/startpage.py
  3. 2
    1
      searx/engines/twitter.py
  4. 1
    2
      searx/engines/xpath.py

+ 2
- 1
searx/engines/duckduckgo.py ファイルの表示

@@ -1,5 +1,6 @@
1 1
 from json import loads
2 2
 from urllib import urlencode
3
+from searx.utils import html_to_text
3 4
 
4 5
 url = 'https://duckduckgo.com/'
5 6
 search_url = url + 'd.js?{query}&l=us-en&p=1&s=0'
@@ -16,7 +17,7 @@ def response(resp):
16 17
         if not r.get('t'):
17 18
             continue
18 19
         results.append({'title': r['t']
19
-                       ,'content': r['a']
20
+                       ,'content': html_to_text(r['a'])
20 21
                        ,'url': r['u']
21 22
                        })
22 23
     return results

+ 2
- 2
searx/engines/startpage.py ファイルの表示

@@ -1,4 +1,4 @@
1
-from urllib import quote
1
+from urllib import urlencode
2 2
 from lxml import html
3 3
 from urlparse import urlparse
4 4
 from cgi import escape
@@ -8,7 +8,7 @@ search_url = base_url+'do/search'
8 8
 
9 9
 def request(query, params):
10 10
     global search_url
11
-    query = quote(query.replace(' ', '+'), safe='+')
11
+    query = urlencode({'q': query})[2:]
12 12
     params['url'] = search_url
13 13
     params['method'] = 'POST'
14 14
     params['data'] = {'query': query}

+ 2
- 1
searx/engines/twitter.py ファイルの表示

@@ -1,6 +1,7 @@
1 1
 from urlparse import urljoin
2 2
 from urllib import urlencode
3 3
 from lxml import html
4
+from cgi import escape
4 5
 
5 6
 categories = ['social media']
6 7
 
@@ -21,6 +22,6 @@ def response(resp):
21 22
         link = tweet.xpath('.//small[@class="time"]//a')[0]
22 23
         url = urljoin(base_url, link.attrib.get('href'))
23 24
         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
+        content = escape(''.join(tweet.xpath('.//p[@class="js-tweet-text tweet-text"]//text()')))
25 26
         results.append({'url': url, 'title': title, 'content': content})
26 27
     return results

+ 1
- 2
searx/engines/xpath.py ファイルの表示

@@ -46,12 +46,11 @@ def request(query, params):
46 46
 def response(resp):
47 47
     results = []
48 48
     dom = html.fromstring(resp.text)
49
-    query = resp.search_params['query']
50 49
     if results_xpath:
51 50
         for result in dom.xpath(results_xpath):
52 51
             url = extract_url(result.xpath(url_xpath))
53 52
             title = ' '.join(result.xpath(title_xpath))
54
-            content = escape(' '.join(result.xpath(content_xpath))).replace(query, '<b>{0}</b>'.format(query))
53
+            content = escape(' '.join(result.xpath(content_xpath)))
55 54
             results.append({'url': url, 'title': title, 'content': content})
56 55
     else:
57 56
         for content, url, title in zip(dom.xpath(content_xpath), map(extract_url, dom.xpath(url_xpath)), dom.xpath(title_xpath)):