.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
goodreads.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""Goodreads (books)
3"""
4
5from urllib.parse import urlencode
6
7from lxml import html
8from searx.utils import extract_text, eval_xpath, eval_xpath_list
9
10about = {
11 'website': 'https://www.goodreads.com',
12 'wikidata_id': 'Q2359213',
13 'official_api_documentation': None,
14 'use_official_api': False,
15 'require_api_key': False,
16 'results': 'HTML',
17}
18categories = []
19paging = True
20
21base_url = "https://www.goodreads.com"
22
23results_xpath = "//table//tr"
24thumbnail_xpath = ".//img[contains(@class, 'bookCover')]/@src"
25url_xpath = ".//a[contains(@class, 'bookTitle')]/@href"
26title_xpath = ".//a[contains(@class, 'bookTitle')]"
27author_xpath = ".//a[contains(@class, 'authorName')]"
28info_text_xpath = ".//span[contains(@class, 'uitext')]"
29
30
31def request(query, params):
32 args = {
33 'q': query,
34 'page': params['pageno'],
35 }
36
37 params['url'] = f"{base_url}/search?{urlencode(args)}"
38 return params
39
40
41def response(resp):
42 results = []
43
44 dom = html.fromstring(resp.text)
45
46 for result in eval_xpath_list(dom, results_xpath):
47 results.append(
48 {
49 'url': base_url + extract_text(eval_xpath(result, url_xpath)),
50 'title': extract_text(eval_xpath(result, title_xpath)),
51 'thumbnail': extract_text(eval_xpath(result, thumbnail_xpath)),
52 'content': extract_text(eval_xpath(result, info_text_xpath)),
53 'metadata': extract_text(eval_xpath(result, author_xpath)),
54 }
55 )
56
57 return results
request(query, params)
Definition goodreads.py:31