.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
uxwing.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""UXwing (images)"""
3
4from urllib.parse import quote_plus
5from lxml import html
6
7from searx.utils import eval_xpath, eval_xpath_list, extract_text
8
9about = {
10 "website": 'https://uxwing.com',
11 "wikidata_id": None,
12 "official_api_documentation": None,
13 "use_official_api": False,
14 "require_api_key": False,
15 "results": 'HTML',
16}
17categories = ['images', 'icons']
18
19base_url = "https://uxwing.com"
20
21
22def request(query, params):
23 params['url'] = f"{base_url}/?s={quote_plus(query)}"
24 return params
25
26
27def response(resp):
28 results = []
29
30 doc = html.fromstring(resp.text)
31 for result in eval_xpath_list(doc, "//article[starts-with(@id, 'post')]"):
32 classes = extract_text(eval_xpath(result, "./@class")).split(" ")
33 tags = []
34 for css_class in classes:
35 for prefix in ("category", "tag"):
36 if css_class.startswith(prefix):
37 tag = css_class.removeprefix(prefix)
38 tags.append(tag.replace("-", " ").title())
39
40 results.append(
41 {
42 'template': 'images.html',
43 'url': extract_text(eval_xpath(result, "./a/@href")),
44 'img_src': extract_text(eval_xpath(result, ".//img/@src")),
45 'title': extract_text(eval_xpath(result, ".//img/@alt")),
46 'content': ', '.join(tags),
47 }
48 )
49
50 return results
request(query, params)
Definition uxwing.py:22