.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
seznam.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""Seznam
3
4"""
5
6from urllib.parse import urlencode
7from lxml import html
8from searx.network import get
9from searx.exceptions import SearxEngineAccessDeniedException
10from searx.utils import (
11 extract_text,
12 eval_xpath_list,
13 eval_xpath_getindex,
14)
15
16# about
17about = {
18 "website": "https://www.seznam.cz/",
19 "wikidata_id": "Q3490485",
20 "official_api_documentation": "https://api.sklik.cz/",
21 "use_official_api": False,
22 "require_api_key": False,
23 "results": "HTML",
24 "language": "cz",
25}
26
27categories = ['general', 'web']
28base_url = 'https://search.seznam.cz/'
29
30
31def request(query, params):
32 response_index = get(base_url, headers=params['headers'], raise_for_httperror=True)
33 dom = html.fromstring(response_index.text)
34
35 url_params = {
36 'q': query,
37 'oq': query,
38 }
39 for e in eval_xpath_list(dom, '//input[@type="hidden"]'):
40 name = e.get('name')
41 value = e.get('value')
42 url_params[name] = value
43
44 params['url'] = base_url + '?' + urlencode(url_params)
45 params['cookies'] = response_index.cookies
46 return params
47
48
49def response(resp):
50 if resp.url.path.startswith('/verify'):
52
53 results = []
54
55 dom = html.fromstring(resp.content.decode())
56 for result_element in eval_xpath_list(
57 dom, '//div[@id="searchpage-root"]//div[@class="Layout--left"]/div[@class="f2c528"]'
58 ):
59 result_data = eval_xpath_getindex(
60 result_element, './/div[@class="c8774a" or @class="e69e8d a11657"]', 0, default=None
61 )
62 if result_data is None:
63 continue
64 title_element = eval_xpath_getindex(result_element, './/h3/a', 0)
65 results.append(
66 {
67 'url': title_element.get('href'),
68 'title': extract_text(title_element),
69 'content': extract_text(result_data),
70 }
71 )
72
73 return results
request(query, params)
Definition seznam.py:31