|
@@ -15,17 +15,20 @@ from searx.utils import is_valid_lang
|
15
|
15
|
from searx.url_utils import urljoin
|
16
|
16
|
|
17
|
17
|
categories = ['general']
|
18
|
|
-url = u'http://dictzone.com/{from_lang}-{to_lang}-dictionary/{query}'
|
|
18
|
+url = u'https://dictzone.com/{from_lang}-{to_lang}-dictionary/{query}'
|
19
|
19
|
weight = 100
|
20
|
20
|
|
21
|
21
|
parser_re = re.compile(b'.*?([a-z]+)-([a-z]+) ([^ ]+)$', re.I)
|
22
|
22
|
results_xpath = './/table[@id="r"]/tr'
|
23
|
23
|
|
24
|
24
|
|
25
|
|
-def request(query, params):
|
26
|
|
- m = parser_re.match(query)
|
|
25
|
+def is_accepted(query, params):
|
|
26
|
+ m = parser_re.match(unicode(query, 'utf8'))
|
27
|
27
|
if not m:
|
28
|
|
- return params
|
|
28
|
+ # wrong query
|
|
29
|
+ return False
|
|
30
|
+
|
|
31
|
+ params["parsed_regex"] = m
|
29
|
32
|
|
30
|
33
|
from_lang, to_lang, query = m.groups()
|
31
|
34
|
|
|
@@ -33,11 +36,23 @@ def request(query, params):
|
33
|
36
|
to_lang = is_valid_lang(to_lang)
|
34
|
37
|
|
35
|
38
|
if not from_lang or not to_lang:
|
|
39
|
+ return False
|
|
40
|
+
|
|
41
|
+ params['from_lang'] = from_lang
|
|
42
|
+ params['to_lang'] = to_lang
|
|
43
|
+ params['query'] = query
|
|
44
|
+
|
|
45
|
+ return True
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+def request(query, params):
|
|
49
|
+ m = params["parsed_regex"]
|
|
50
|
+ if not m:
|
36
|
51
|
return params
|
37
|
52
|
|
38
|
|
- params['url'] = url.format(from_lang=from_lang[2],
|
39
|
|
- to_lang=to_lang[2],
|
40
|
|
- query=query.decode('utf-8'))
|
|
53
|
+ params['url'] = url.format(from_lang=params['from_lang'][2],
|
|
54
|
+ to_lang=params['to_lang'][2],
|
|
55
|
+ query=params['query'])
|
41
|
56
|
|
42
|
57
|
return params
|
43
|
58
|
|
|
@@ -45,6 +60,9 @@ def request(query, params):
|
45
|
60
|
def response(resp):
|
46
|
61
|
results = []
|
47
|
62
|
|
|
63
|
+ if resp.status_code != 200:
|
|
64
|
+ return results
|
|
65
|
+
|
48
|
66
|
dom = html.fromstring(resp.text)
|
49
|
67
|
|
50
|
68
|
for k, result in enumerate(dom.xpath(results_xpath)[1:]):
|
|
@@ -61,7 +79,10 @@ def response(resp):
|
61
|
79
|
|
62
|
80
|
results.append({
|
63
|
81
|
'url': urljoin(resp.url, '?%d' % k),
|
64
|
|
- 'title': from_result.text_content(),
|
|
82
|
+ 'title': '[{0}-{1}] {2}'.format(
|
|
83
|
+ resp.search_params['from_lang'][1],
|
|
84
|
+ resp.search_params['to_lang'][1],
|
|
85
|
+ from_result.text_content()),
|
65
|
86
|
'content': '; '.join(to_results)
|
66
|
87
|
})
|
67
|
88
|
|