Ponysearch/searx/engines/fdroid.py

51 lines
1.4 KiB
Python
Raw Normal View History

2016-03-26 22:50:44 +01:00
"""
F-Droid (a repository of FOSS applications for Android)
@website https://f-droid.org/
@provide-api no
@using-api no
@results HTML
@stable no (HTML can change)
@parse url, title, content
"""
from urllib.parse import urlencode
2016-03-26 22:50:44 +01:00
from lxml import html
2016-11-30 18:43:03 +01:00
from searx.engines.xpath import extract_text
2016-03-26 22:50:44 +01:00
# engine dependent config
categories = ['files']
paging = True
# search-url
2019-08-05 15:44:02 +02:00
base_url = 'https://search.f-droid.org/'
search_url = base_url + '?{query}'
2016-03-26 22:50:44 +01:00
# do search-request
def request(query, params):
2019-08-05 15:44:02 +02:00
query = urlencode({'q': query, 'page': params['pageno'], 'lang': ''})
2016-03-26 22:50:44 +01:00
params['url'] = search_url.format(query=query)
return params
# get response from search-request
def response(resp):
results = []
dom = html.fromstring(resp.text)
2019-08-05 15:44:02 +02:00
for app in dom.xpath('//a[@class="package-header"]'):
app_url = app.xpath('./@href')[0]
app_title = extract_text(app.xpath('./div/h4[@class="package-name"]/text()'))
app_content = extract_text(app.xpath('./div/div/span[@class="package-summary"]')).strip() \
+ ' - ' + extract_text(app.xpath('./div/div/span[@class="package-license"]')).strip()
app_img_src = app.xpath('./img[@class="package-icon"]/@src')[0]
results.append({'url': app_url,
'title': app_title,
'content': app_content,
'img_src': app_img_src})
2016-03-26 22:50:44 +01:00
return results