.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.mojeek Namespace Reference

Functions

 init (_)
 request (query, params)
 _general_results (dom)
 _image_results (dom)
 _news_results (dom)
 response (resp)
 fetch_traits (EngineTraits engine_traits)

Variables

dict about
bool paging = True
bool safesearch = True
bool time_range_support = True
int max_page = 10
str base_url = "https://www.mojeek.com"
list categories = ["general", "web"]
str search_type = ""
str results_xpath = '//ul[@class="results-standard"]/li/a[@class="ob"]'
str url_xpath = './@href'
str title_xpath = '../h2/a'
str content_xpath = '..//p[@class="s"]'
str suggestion_xpath = '//div[@class="top-info"]/p[@class="top-info spell"]/em/a'
str image_results_xpath = '//div[@id="results"]/div[contains(@class, "image")]'
str image_url_xpath = './a/@href'
str image_title_xpath = './a/@data-title'
str image_img_src_xpath = './a/img/@src'
str news_results_xpath = '//section[contains(@class, "news-search-result")]//article'
str news_url_xpath = './/h2/a/@href'
str news_title_xpath = './/h2/a'
str news_content_xpath = './/p[@class="s"]'
str language_param = 'lb'
str region_param = 'arc'
dict _delta_kwargs = {'day': 'days', 'week': 'weeks', 'month': 'months', 'year': 'years'}

Detailed Description

Mojeek (general, images, news)

Function Documentation

◆ _general_results()

searx.engines.mojeek._general_results ( dom)
protected

Definition at line 81 of file mojeek.py.

81def _general_results(dom):
82 results = []
83
84 for result in eval_xpath_list(dom, results_xpath):
85 results.append(
86 {
87 'url': extract_text(eval_xpath(result, url_xpath)),
88 'title': extract_text(eval_xpath(result, title_xpath)),
89 'content': extract_text(eval_xpath(result, content_xpath)),
90 }
91 )
92
93 for suggestion in eval_xpath(dom, suggestion_xpath):
94 results.append({'suggestion': extract_text(suggestion)})
95
96 return results
97
98

Referenced by response().

Here is the caller graph for this function:

◆ _image_results()

searx.engines.mojeek._image_results ( dom)
protected

Definition at line 99 of file mojeek.py.

99def _image_results(dom):
100 results = []
101
102 for result in eval_xpath_list(dom, image_results_xpath):
103 results.append(
104 {
105 'template': 'images.html',
106 'url': extract_text(eval_xpath(result, image_url_xpath)),
107 'title': extract_text(eval_xpath(result, image_title_xpath)),
108 'img_src': base_url + extract_text(eval_xpath(result, image_img_src_xpath)), # type: ignore
109 'content': '',
110 }
111 )
112
113 return results
114
115

Referenced by response().

Here is the caller graph for this function:

◆ _news_results()

searx.engines.mojeek._news_results ( dom)
protected

Definition at line 116 of file mojeek.py.

116def _news_results(dom):
117 results = []
118
119 for result in eval_xpath_list(dom, news_results_xpath):
120 results.append(
121 {
122 'url': extract_text(eval_xpath(result, news_url_xpath)),
123 'title': extract_text(eval_xpath(result, news_title_xpath)),
124 'content': extract_text(eval_xpath(result, news_content_xpath)),
125 }
126 )
127
128 return results
129
130

Referenced by response().

Here is the caller graph for this function:

◆ fetch_traits()

searx.engines.mojeek.fetch_traits ( EngineTraits engine_traits)

Definition at line 146 of file mojeek.py.

146def fetch_traits(engine_traits: EngineTraits):
147 # pylint: disable=import-outside-toplevel
148 from searx import network
149 from searx.locales import get_official_locales, region_tag
150 from babel import Locale, UnknownLocaleError
151 import contextlib
152
153 resp = network.get(base_url + "/preferences", headers={'Accept-Language': 'en-US,en;q=0.5'})
154 dom = html.fromstring(resp.text) # type: ignore
155
156 languages = eval_xpath_list(dom, f'//select[@name="{language_param}"]/option/@value')
157
158 engine_traits.custom['language_all'] = languages[0]
159
160 for code in languages[1:]:
161 with contextlib.suppress(UnknownLocaleError):
162 locale = Locale(code)
163 engine_traits.languages[locale.language] = code
164
165 regions = eval_xpath_list(dom, f'//select[@name="{region_param}"]/option/@value')
166
167 engine_traits.custom['region_all'] = regions[1]
168
169 for code in regions[2:]:
170 for locale in get_official_locales(code, engine_traits.languages):
171 engine_traits.regions[region_tag(locale)] = code

◆ init()

searx.engines.mojeek.init ( _)

Definition at line 52 of file mojeek.py.

52def init(_):
53 if search_type not in ('', 'images', 'news'):
54 raise ValueError(f"Invalid search type {search_type}")
55
56

◆ request()

searx.engines.mojeek.request ( query,
params )

Definition at line 57 of file mojeek.py.

57def request(query, params):
58 args = {
59 'q': query,
60 'safe': min(params['safesearch'], 1),
61 language_param: traits.get_language(params['searxng_locale'], traits.custom['language_all']),
62 region_param: traits.get_region(params['searxng_locale'], traits.custom['region_all']),
63 }
64
65 if search_type:
66 args['fmt'] = search_type
67
68 if search_type == '':
69 args['s'] = 10 * (params['pageno'] - 1)
70
71 if params['time_range'] and search_type != 'images':
72 kwargs = {_delta_kwargs[params['time_range']]: 1}
73 args["since"] = (datetime.now() - relativedelta(**kwargs)).strftime("%Y%m%d") # type: ignore
74 logger.debug(args["since"])
75
76 params['url'] = f"{base_url}/search?{urlencode(args)}"
77
78 return params
79
80

◆ response()

searx.engines.mojeek.response ( resp)

Definition at line 131 of file mojeek.py.

131def response(resp):
132 dom = html.fromstring(resp.text)
133
134 if search_type == '':
135 return _general_results(dom)
136
137 if search_type == 'images':
138 return _image_results(dom)
139
140 if search_type == 'news':
141 return _news_results(dom)
142
143 raise ValueError(f"Invalid search type {search_type}")
144
145

References _general_results(), _image_results(), and _news_results().

Here is the call graph for this function:

Variable Documentation

◆ _delta_kwargs

dict searx.engines.mojeek._delta_kwargs = {'day': 'days', 'week': 'weeks', 'month': 'months', 'year': 'years'}
protected

Definition at line 49 of file mojeek.py.

◆ about

dict searx.engines.mojeek.about
Initial value:
1= {
2 'website': 'https://mojeek.com',
3 'wikidata_id': 'Q60747299',
4 'official_api_documentation': 'https://www.mojeek.com/support/api/search/request_parameters.html',
5 'use_official_api': False,
6 'require_api_key': False,
7 'results': 'HTML',
8}

Definition at line 12 of file mojeek.py.

◆ base_url

str searx.engines.mojeek.base_url = "https://www.mojeek.com"

Definition at line 25 of file mojeek.py.

◆ categories

list searx.engines.mojeek.categories = ["general", "web"]

Definition at line 27 of file mojeek.py.

◆ content_xpath

str searx.engines.mojeek.content_xpath = '..//p[@class="s"]'

Definition at line 33 of file mojeek.py.

◆ image_img_src_xpath

str searx.engines.mojeek.image_img_src_xpath = './a/img/@src'

Definition at line 39 of file mojeek.py.

◆ image_results_xpath

str searx.engines.mojeek.image_results_xpath = '//div[@id="results"]/div[contains(@class, "image")]'

Definition at line 36 of file mojeek.py.

◆ image_title_xpath

str searx.engines.mojeek.image_title_xpath = './a/@data-title'

Definition at line 38 of file mojeek.py.

◆ image_url_xpath

str searx.engines.mojeek.image_url_xpath = './a/@href'

Definition at line 37 of file mojeek.py.

◆ language_param

str searx.engines.mojeek.language_param = 'lb'

Definition at line 46 of file mojeek.py.

◆ max_page

int searx.engines.mojeek.max_page = 10

Definition at line 23 of file mojeek.py.

◆ news_content_xpath

str searx.engines.mojeek.news_content_xpath = './/p[@class="s"]'

Definition at line 44 of file mojeek.py.

◆ news_results_xpath

str searx.engines.mojeek.news_results_xpath = '//section[contains(@class, "news-search-result")]//article'

Definition at line 41 of file mojeek.py.

◆ news_title_xpath

str searx.engines.mojeek.news_title_xpath = './/h2/a'

Definition at line 43 of file mojeek.py.

◆ news_url_xpath

str searx.engines.mojeek.news_url_xpath = './/h2/a/@href'

Definition at line 42 of file mojeek.py.

◆ paging

bool searx.engines.mojeek.paging = True

Definition at line 20 of file mojeek.py.

◆ region_param

str searx.engines.mojeek.region_param = 'arc'

Definition at line 47 of file mojeek.py.

◆ results_xpath

str searx.engines.mojeek.results_xpath = '//ul[@class="results-standard"]/li/a[@class="ob"]'

Definition at line 30 of file mojeek.py.

◆ safesearch

bool searx.engines.mojeek.safesearch = True

Definition at line 21 of file mojeek.py.

◆ search_type

str searx.engines.mojeek.search_type = ""

Definition at line 28 of file mojeek.py.

◆ suggestion_xpath

str searx.engines.mojeek.suggestion_xpath = '//div[@class="top-info"]/p[@class="top-info spell"]/em/a'

Definition at line 34 of file mojeek.py.

◆ time_range_support

bool searx.engines.mojeek.time_range_support = True

Definition at line 22 of file mojeek.py.

◆ title_xpath

str searx.engines.mojeek.title_xpath = '../h2/a'

Definition at line 32 of file mojeek.py.

◆ url_xpath

str searx.engines.mojeek.url_xpath = './@href'

Definition at line 31 of file mojeek.py.