.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 69 of file naver.py.

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

◆ parse_general()

searx.engines.naver.parse_general ( data)

Definition at line 96 of file naver.py.

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

◆ parse_images()

searx.engines.naver.parse_images ( data)

Definition at line 122 of file naver.py.

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

◆ parse_news()

searx.engines.naver.parse_news ( data)

Definition at line 146 of file naver.py.

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

◆ parse_videos()

searx.engines.naver.parse_videos ( data)

Definition at line 182 of file naver.py.

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

◆ request()

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

Definition at line 74 of file naver.py.

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

◆ response()

EngineResults searx.engines.naver.response ( resp)

Definition at line 90 of file naver.py.

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

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 22 of file naver.py.

◆ base_url

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

Definition at line 37 of file naver.py.

◆ categories

list searx.engines.naver.categories = []

Definition at line 31 of file naver.py.

◆ naver_category

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

Definition at line 39 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 49 of file naver.py.

◆ paging

bool searx.engines.naver.paging = True

Definition at line 32 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 35 of file naver.py.

◆ time_range_support

bool searx.engines.naver.time_range_support = True

Definition at line 34 of file naver.py.