.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
openclipart.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""OpenClipArt (images)"""
3
4from urllib.parse import urlencode
5from lxml import html
6from searx.utils import extract_text, eval_xpath, eval_xpath_list
7
8about = {
9 "website": 'https://openclipart.org/',
10 "wikidata_id": 'Q979593',
11 "official_api_documentation": None,
12 "use_official_api": False,
13 "require_api_key": False,
14 "results": 'HTML',
15}
16
17categories = ['images']
18paging = True
19
20base_url = "https://openclipart.org"
21
22
23def request(query, params):
24 args = {
25 'query': query,
26 'p': params['pageno'],
27 }
28 params['url'] = f"{base_url}/search/?{urlencode(args)}"
29 return params
30
31
32def response(resp):
33 results = []
34
35 dom = html.fromstring(resp.text)
36
37 for result in eval_xpath_list(dom, "//div[contains(@class, 'gallery')]/div[contains(@class, 'artwork')]"):
38 results.append(
39 {
40 'template': 'images.html',
41 'url': base_url + extract_text(eval_xpath(result, "./a/@href")),
42 'title': extract_text(eval_xpath(result, "./a/img/@alt")),
43 'img_src': base_url + extract_text(eval_xpath(result, "./a/img/@src")),
44 }
45 )
46
47 return results