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

Functions

 catch_bad_response (resp)
 
 request (query, params)
 
 response (resp)
 

Variables

dict about
 
list categories = []
 
bool paging = True
 
str search_type = ""
 
str base_url_web = 'https://yandex.com/search/site/'
 
str base_url_images = 'https://yandex.com/images/search'
 
str results_xpath = '//li[contains(@class, "serp-item")]'
 
str url_xpath = './/a[@class="b-serp-item__title-link"]/@href'
 
str title_xpath = './/h3[@class="b-serp-item__title"]/a[@class="b-serp-item__title-link"]/span'
 
str content_xpath = './/div[@class="b-serp-item__content"]//div[@class="b-serp-item__text"]'
 

Detailed Description

Yandex (Web, images)

Function Documentation

◆ catch_bad_response()

searx.engines.yandex.catch_bad_response ( resp)

Definition at line 37 of file yandex.py.

37def catch_bad_response(resp):
38 if resp.url.path.startswith('/showcaptcha'):
39 raise SearxEngineCaptchaException()
40
41

Referenced by searx.engines.yandex.response().

+ Here is the caller graph for this function:

◆ request()

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

Definition at line 42 of file yandex.py.

42def request(query, params):
43 query_params_web = {
44 "tmpl_version": "releases",
45 "text": query,
46 "web": "1",
47 "frame": "1",
48 "searchid": "3131712",
49 }
50
51 query_params_images = {
52 "text": query,
53 "uinfo": "sw-1920-sh-1080-ww-1125-wh-999",
54 }
55
56 if params['pageno'] > 1:
57 query_params_web.update({"p": params["pageno"] - 1})
58 query_params_images.update({"p": params["pageno"] - 1})
59
60 params["cookies"] = {'cookie': "yp=1716337604.sp.family%3A0#1685406411.szm.1:1920x1080:1920x999"}
61
62 if search_type == 'web':
63 params['url'] = f"{base_url_web}?{urlencode(query_params_web)}"
64 elif search_type == 'images':
65 params['url'] = f"{base_url_images}?{urlencode(query_params_images)}"
66
67 return params
68
69

◆ response()

searx.engines.yandex.response ( resp)

Definition at line 70 of file yandex.py.

70def response(resp):
71 if search_type == 'web':
72
73 catch_bad_response(resp)
74
75 dom = html.fromstring(resp.text)
76
77 results = []
78
79 for result in eval_xpath_list(dom, results_xpath):
80 results.append(
81 {
82 'url': extract_text(eval_xpath(result, url_xpath)),
83 'title': extract_text(eval_xpath(result, title_xpath)),
84 'content': extract_text(eval_xpath(result, content_xpath)),
85 }
86 )
87
88 return results
89
90 if search_type == 'images':
91
92 catch_bad_response(resp)
93
94 html_data = html.fromstring(resp.text)
95 html_sample = unescape(html.tostring(html_data, encoding='unicode'))
96
97 content_between_tags = extr(
98 html_sample, '{"location":"/images/search/', 'advRsyaSearchColumn":null}}', default="fail"
99 )
100 json_data = '{"location":"/images/search/' + content_between_tags + 'advRsyaSearchColumn":null}}'
101
102 if content_between_tags == "fail":
103 content_between_tags = extr(html_sample, '{"location":"/images/search/', 'false}}}')
104 json_data = '{"location":"/images/search/' + content_between_tags + 'false}}}'
105
106 json_resp = loads(json_data)
107
108 results = []
109 for _, item_data in json_resp['initialState']['serpList']['items']['entities'].items():
110 title = item_data['snippet']['title']
111 source = item_data['snippet']['url']
112 thumb = item_data['image']
113 fullsize_image = item_data['viewerData']['dups'][0]['url']
114 height = item_data['viewerData']['dups'][0]['h']
115 width = item_data['viewerData']['dups'][0]['w']
116 filesize = item_data['viewerData']['dups'][0]['fileSizeInBytes']
117 humanized_filesize = humanize_bytes(filesize)
118
119 results.append(
120 {
121 'title': title,
122 'url': source,
123 'img_src': fullsize_image,
124 'filesize': humanized_filesize,
125 'thumbnail_src': thumb,
126 'template': 'images.html',
127 'resolution': f'{width} x {height}',
128 }
129 )
130
131 return results
132
133 return []

References searx.engines.yandex.catch_bad_response().

+ Here is the call graph for this function:

Variable Documentation

◆ about

dict searx.engines.yandex.about
Initial value:
1= {
2 "website": 'https://yandex.com/',
3 "wikidata_id": 'Q5281',
4 "official_api_documentation": "?",
5 "use_official_api": False,
6 "require_api_key": False,
7 "results": 'HTML',
8}

Definition at line 13 of file yandex.py.

◆ base_url_images

str searx.engines.yandex.base_url_images = 'https://yandex.com/images/search'

Definition at line 29 of file yandex.py.

◆ base_url_web

str searx.engines.yandex.base_url_web = 'https://yandex.com/search/site/'

Definition at line 28 of file yandex.py.

◆ categories

list searx.engines.yandex.categories = []

Definition at line 23 of file yandex.py.

◆ content_xpath

str searx.engines.yandex.content_xpath = './/div[@class="b-serp-item__content"]//div[@class="b-serp-item__text"]'

Definition at line 34 of file yandex.py.

◆ paging

bool searx.engines.yandex.paging = True

Definition at line 24 of file yandex.py.

◆ results_xpath

str searx.engines.yandex.results_xpath = '//li[contains(@class, "serp-item")]'

Definition at line 31 of file yandex.py.

◆ search_type

str searx.engines.yandex.search_type = ""

Definition at line 25 of file yandex.py.

◆ title_xpath

str searx.engines.yandex.title_xpath = './/h3[@class="b-serp-item__title"]/a[@class="b-serp-item__title-link"]/span'

Definition at line 33 of file yandex.py.

◆ url_xpath

str searx.engines.yandex.url_xpath = './/a[@class="b-serp-item__title-link"]/@href'

Definition at line 32 of file yandex.py.