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

Functions

 init (_)
 request (query, params)
EngineResults response (resp)
 parse_general (data)
 parse_images (data)
 parse_news (data)
 parse_videos (data)

Variables

dict about
list categories = []
bool paging = True
bool time_range_support = True
dict time_range_dict = {"day": "1d", "week": "1w", "month": "1m", "year": "1y"}
str base_url = "https://search.naver.com"
str naver_category = "general"
dict naver_category_dict

Detailed Description

Naver for SearXNG

Function Documentation

◆ init()

searx.engines.naver.init ( _)

Definition at line 70 of file naver.py.

70def init(_):
71 if naver_category not in ('general', 'images', 'news', 'videos'):
72 raise SearxEngineAPIException(f"Unsupported category: {naver_category}")
73
74

◆ parse_general()

searx.engines.naver.parse_general ( data)

Definition at line 97 of file naver.py.

97def parse_general(data):
98 results = EngineResults()
99
100 dom = html.fromstring(data)
101
102 for item in eval_xpath_list(dom, "//ul[contains(@class, 'lst_total')]/li[contains(@class, 'bx')]"):
103 thumbnail = None
104 try:
105 thumbnail = eval_xpath_getindex(item, ".//div[contains(@class, 'thumb_single')]//img/@data-lazysrc", 0)
106 except (ValueError, TypeError, SearxEngineXPathException):
107 pass
108
109 results.add(
110 MainResult(
111 title=extract_text(eval_xpath(item, ".//a[contains(@class, 'link_tit')]")),
112 url=eval_xpath_getindex(item, ".//a[contains(@class, 'link_tit')]/@href", 0),
113 content=extract_text(
114 eval_xpath(item, ".//div[contains(@class, 'total_dsc_wrap')]//a[contains(@class, 'api_txt_lines')]")
115 ),
116 thumbnail=thumbnail,
117 )
118 )
119
120 return results
121
122

◆ parse_images()

searx.engines.naver.parse_images ( data)

Definition at line 123 of file naver.py.

123def parse_images(data):
124 results = []
125
126 match = extr(data, '<script>var imageSearchTabData=', '</script>')
127 if match:
128 json = js_variable_to_python(match.strip())
129 items = json.get('content', {}).get('items', [])
130
131 for item in items:
132 results.append(
133 {
134 "template": "images.html",
135 "url": item.get('link'),
136 "thumbnail_src": item.get('thumb'),
137 "img_src": item.get('originalUrl'),
138 "title": html_to_text(item.get('title')),
139 "source": item.get('source'),
140 "resolution": f"{item.get('orgWidth')} x {item.get('orgHeight')}",
141 }
142 )
143
144 return results
145
146

◆ parse_news()

searx.engines.naver.parse_news ( data)

Definition at line 147 of file naver.py.

147def parse_news(data):
148 results = EngineResults()
149 dom = html.fromstring(data)
150
151 for item in eval_xpath_list(
152 dom, "//div[contains(@class, 'sds-comps-base-layout') and contains(@class, 'sds-comps-full-layout')]"
153 ):
154 title = extract_text(eval_xpath(item, ".//span[contains(@class, 'sds-comps-text-type-headline1')]/text()"))
155
156 url = eval_xpath_getindex(item, ".//a[@href and @nocr='1']/@href", 0)
157
158 content = extract_text(eval_xpath(item, ".//span[contains(@class, 'sds-comps-text-type-body1')]"))
159
160 thumbnail = None
161 try:
162 thumbnail = eval_xpath_getindex(
163 item,
164 ".//div[contains(@class, 'sds-comps-image') and contains(@class, 'sds-rego-thumb-overlay')]//img[@src]/@src",
165 0,
166 )
167 except (ValueError, TypeError, SearxEngineXPathException):
168 pass
169
170 if title and content and url:
171 results.add(
172 MainResult(
173 title=title,
174 url=url,
175 content=content,
176 thumbnail=thumbnail,
177 )
178 )
179
180 return results
181
182

◆ parse_videos()

searx.engines.naver.parse_videos ( data)

Definition at line 183 of file naver.py.

183def parse_videos(data):
184 results = []
185
186 dom = html.fromstring(data)
187
188 for item in eval_xpath_list(dom, "//li[contains(@class, 'video_item')]"):
189 url = eval_xpath_getindex(item, ".//a[contains(@class, 'info_title')]/@href", 0)
190
191 thumbnail = None
192 try:
193 thumbnail = eval_xpath_getindex(item, ".//img[contains(@class, 'thumb')]/@src", 0)
194 except (ValueError, TypeError, SearxEngineXPathException):
195 pass
196
197 length = None
198 try:
199 length = parse_duration_string(extract_text(eval_xpath(item, ".//span[contains(@class, 'time')]")))
200 except (ValueError, TypeError):
201 pass
202
203 results.append(
204 {
205 "template": "videos.html",
206 "title": extract_text(eval_xpath(item, ".//a[contains(@class, 'info_title')]")),
207 "url": url,
208 "thumbnail": thumbnail,
209 "length": length,
210 "iframe_src": get_embeded_stream_url(url),
211 }
212 )
213
214 return results

◆ request()

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

Definition at line 75 of file naver.py.

75def request(query, params):
76 query_params = {
77 "query": query,
78 }
79
80 if naver_category in naver_category_dict:
81 query_params["start"] = (params["pageno"] - 1) * naver_category_dict[naver_category]["start"] + 1
82 query_params["where"] = naver_category_dict[naver_category]["where"]
83
84 if params["time_range"] in time_range_dict:
85 query_params["nso"] = f"p:{time_range_dict[params['time_range']]}"
86
87 params["url"] = f"{base_url}/search.naver?{urlencode(query_params)}"
88 return params
89
90

◆ response()

EngineResults searx.engines.naver.response ( resp)

Definition at line 91 of file naver.py.

91def response(resp) -> EngineResults:
92 parsers = {'general': parse_general, 'images': parse_images, 'news': parse_news, 'videos': parse_videos}
93
94 return parsers[naver_category](resp.text)
95
96

Variable Documentation

◆ about

dict searx.engines.naver.about
Initial value:
1= {
2 "website": "https://search.naver.com",
3 "wikidata_id": "Q485639",
4 "use_official_api": False,
5 "require_api_key": False,
6 "results": "HTML",
7 "language": "ko",
8}

Definition at line 23 of file naver.py.

◆ base_url

str searx.engines.naver.base_url = "https://search.naver.com"

Definition at line 38 of file naver.py.

◆ categories

list searx.engines.naver.categories = []

Definition at line 32 of file naver.py.

◆ naver_category

str searx.engines.naver.naver_category = "general"

Definition at line 40 of file naver.py.

◆ naver_category_dict

dict searx.engines.naver.naver_category_dict
Initial value:
1= {
2 "general": {
3 "start": 15,
4 "where": "web",
5 },
6 "images": {
7 "start": 50,
8 "where": "image",
9 },
10 "news": {
11 "start": 10,
12 "where": "news",
13 },
14 "videos": {
15 "start": 48,
16 "where": "video",
17 },
18}

Definition at line 50 of file naver.py.

◆ paging

bool searx.engines.naver.paging = True

Definition at line 33 of file naver.py.

◆ time_range_dict

dict searx.engines.naver.time_range_dict = {"day": "1d", "week": "1w", "month": "1m", "year": "1y"}

Definition at line 36 of file naver.py.

◆ time_range_support

bool searx.engines.naver.time_range_support = True

Definition at line 35 of file naver.py.