@@ -0,0 +1,57 @@
1+
2+"""Onesearch
3+"""
4+
5+from lxml.html import fromstring
6+
7+import re
8+
9+from searx.utils import (
10+ eval_xpath,
11+ extract_text,
12+)
13+
14+from urllib.parse import unquote
15+
16+# about
17+about = {
18+ "website": 'https://www.onesearch.com/',
19+ "wikidata_id": None,
20+ "use_official_api": False,
21+ "require_api_key": False,
22+ "results": 'HTML',
23+}
24+
25+# engine dependent config
26+categories = ['general']
27+paging = True
28+
29+# search-url
30+URL = 'https://www.onesearch.com/yhs/search;?p=%s&b=%d'
31+
32+
33+def request(query, params):
34+ starting_from = (params['pageno'] * 10) - 9
35+ params['url'] = URL % (query, starting_from)
36+ return params
37+
38+
39+# get response from search-request
40+def response(resp):
41+
42+ results = []
43+ doc = fromstring(resp.text)
44+
45+ titles_tags = eval_xpath(doc, '//div[contains(@class, "algo")]//h3[contains(@class, "title")]')
46+ contents = eval_xpath(doc, '//div[contains(@class, "algo")]/div[contains(@class, "compText")]/p')
47+ onesearch_urls = eval_xpath(doc, '//div[contains(@class, "algo")]//h3[contains(@class, "title")]/a/@href')
48+
49+ for title_tag, content, onesearch_url in zip(titles_tags, contents, onesearch_urls):
50+ matches = re.search(r'RU=(.*?)\/', onesearch_url)
51+ results.append({
52+ 'title': title_tag.text_content(),
53+ 'content': extract_text(content),
54+ 'url': unquote(matches.group(1)),
55+ })
56+
57+ return results