.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
www1x.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""1x (Images)
3
4"""
5
6from urllib.parse import urlencode, urljoin
7from lxml import html, etree
8
9from searx.utils import extract_text, eval_xpath_list, eval_xpath_getindex
10
11# about
12about = {
13 "website": 'https://1x.com/',
14 "wikidata_id": None,
15 "official_api_documentation": None,
16 "use_official_api": False,
17 "require_api_key": False,
18 "results": 'HTML',
19}
20
21# engine dependent config
22categories = ['images']
23paging = False
24
25# search-url
26base_url = 'https://1x.com'
27search_url = base_url + '/backend/search.php?{query}'
28gallery_url = 'https://gallery.1x.com/'
29
30
31# do search-request
32def request(query, params):
33 params['url'] = search_url.format(query=urlencode({'q': query}))
34
35 return params
36
37
38# get response from search-request
39def response(resp):
40 results = []
41 xmldom = etree.fromstring(resp.content)
42 xmlsearchresult = eval_xpath_getindex(xmldom, '//data', 0)
43 dom = html.fragment_fromstring(xmlsearchresult.text, create_parent='div')
44 for link in eval_xpath_list(dom, '//a'):
45 url = urljoin(base_url, link.attrib.get('href'))
46 title = extract_text(link)
47 thumbnail_src = urljoin(
48 gallery_url, (eval_xpath_getindex(link, './/img', 0).attrib['src']).replace(base_url, '')
49 )
50 # append result
51 results.append(
52 {
53 'url': url,
54 'title': title,
55 'img_src': thumbnail_src,
56 'content': '',
57 'thumbnail_src': thumbnail_src,
58 'template': 'images.html',
59 }
60 )
61
62 # return results
63 return results
request(query, params)
Definition www1x.py:32