on master help sign in
Merge pull request #3065 from e-foundation/onesearch-engine

Onesearch engine

commitf2f72575023b9a08081f6c87bf309f1f12fa9978 authorNoémi Ványi <kvch@users.noreply.github.com> dateMon 22 Nov 2021, 20:04 (5 years ago) parent4d36aeeb90616a
2 files changed+67
searx/engines/onesearch.py+57 searx/settings.yml+10
searx/engines/onesearch.pynew file+57
@@ -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
searx/settings.yml+10
@@ -1622,6 +1622,16 @@ engines:
16221622 require_api_key: false
16231623 results: HTML
16241624
1625+ - name: onesearch
1626+ shortcut: onesearch
1627+ engine: onesearch
1628+ about:
1629+ website: https://www.onesearch.com/
1630+ wikidata_id: None
1631+ use_official_api: false
1632+ require_api_key: false
1633+ results: HTML
1634+
16251635# Doku engine lets you access to any Doku wiki instance:
16261636# A public one or a private/corporate one.
16271637# - name : ubuntuwiki