.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'}
 
 logger = logging.getLogger()
 

Detailed Description

Mojeek (general, images, news)

Function Documentation

◆ _general_results()

searx.engines.mojeek._general_results ( dom)
protected

Definition at line 90 of file mojeek.py.

90def _general_results(dom):
91 results = []
92
93 for result in eval_xpath_list(dom, results_xpath):
94 results.append(
95 {
96 'url': extract_text(eval_xpath(result, url_xpath)),
97 'title': extract_text(eval_xpath(result, title_xpath)),
98 'content': extract_text(eval_xpath(result, content_xpath)),
99 }
100 )
101
102 for suggestion in eval_xpath(dom, suggestion_xpath):
103 results.append({'suggestion': extract_text(suggestion)})
104
105 return results
106
107

Referenced by response().

+ Here is the caller graph for this function:

◆ _image_results()

searx.engines.mojeek._image_results ( dom)
protected

Definition at line 108 of file mojeek.py.

108def _image_results(dom):
109 results = []
110
111 for result in eval_xpath_list(dom, image_results_xpath):
112 results.append(
113 {
114 'template': 'images.html',
115 'url': extract_text(eval_xpath(result, image_url_xpath)),
116 'title': extract_text(eval_xpath(result, image_title_xpath)),
117 'img_src': base_url + extract_text(eval_xpath(result, image_img_src_xpath)), # type: ignore
118 'content': '',
119 }
120 )
121
122 return results
123
124

Referenced by response().

+ Here is the caller graph for this function:

◆ _news_results()

searx.engines.mojeek._news_results ( dom)
protected

Definition at line 125 of file mojeek.py.

125def _news_results(dom):
126 results = []
127
128 for result in eval_xpath_list(dom, news_results_xpath):
129 results.append(
130 {
131 'url': extract_text(eval_xpath(result, news_url_xpath)),
132 'title': extract_text(eval_xpath(result, news_title_xpath)),
133 'content': extract_text(eval_xpath(result, news_content_xpath)),
134 }
135 )
136
137 return results
138
139

Referenced by response().

+ Here is the caller graph for this function:

◆ fetch_traits()

searx.engines.mojeek.fetch_traits ( EngineTraits engine_traits)

Definition at line 155 of file mojeek.py.

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

◆ init()

searx.engines.mojeek.init ( _)

Definition at line 61 of file mojeek.py.

61def init(_):
62 if search_type not in ('', 'images', 'news'):
63 raise ValueError(f"Invalid search type {search_type}")
64
65

◆ request()

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

Definition at line 66 of file mojeek.py.

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

◆ response()

searx.engines.mojeek.response ( resp)

Definition at line 140 of file mojeek.py.

140def response(resp):
141 dom = html.fromstring(resp.text)
142
143 if search_type == '':
144 return _general_results(dom)
145
146 if search_type == 'images':
147 return _image_results(dom)
148
149 if search_type == 'news':
150 return _news_results(dom)
151
152 raise ValueError(f"Invalid search type {search_type}")
153
154

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 51 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 14 of file mojeek.py.

◆ base_url

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

Definition at line 27 of file mojeek.py.

◆ categories

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

Definition at line 29 of file mojeek.py.

◆ content_xpath

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

Definition at line 35 of file mojeek.py.

◆ image_img_src_xpath

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

Definition at line 41 of file mojeek.py.

◆ image_results_xpath

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

Definition at line 38 of file mojeek.py.

◆ image_title_xpath

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

Definition at line 40 of file mojeek.py.

◆ image_url_xpath

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

Definition at line 39 of file mojeek.py.

◆ language_param

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

Definition at line 48 of file mojeek.py.

◆ logger

searx.engines.mojeek.logger = logging.getLogger()

Definition at line 56 of file mojeek.py.

◆ max_page

int searx.engines.mojeek.max_page = 10

Definition at line 25 of file mojeek.py.

◆ news_content_xpath

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

Definition at line 46 of file mojeek.py.

◆ news_results_xpath

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

Definition at line 43 of file mojeek.py.

◆ news_title_xpath

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

Definition at line 45 of file mojeek.py.

◆ news_url_xpath

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

Definition at line 44 of file mojeek.py.

◆ paging

bool searx.engines.mojeek.paging = True

Definition at line 22 of file mojeek.py.

◆ region_param

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

Definition at line 49 of file mojeek.py.

◆ results_xpath

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

Definition at line 32 of file mojeek.py.

◆ safesearch

bool searx.engines.mojeek.safesearch = True

Definition at line 23 of file mojeek.py.

◆ search_type

str searx.engines.mojeek.search_type = ""

Definition at line 30 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 36 of file mojeek.py.

◆ time_range_support

bool searx.engines.mojeek.time_range_support = True

Definition at line 24 of file mojeek.py.

◆ title_xpath

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

Definition at line 34 of file mojeek.py.

◆ url_xpath

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

Definition at line 33 of file mojeek.py.