.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
rottentomatoes.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""RottenTomatoes (movies)
3"""
4
5from urllib.parse import quote_plus
6from lxml import html
7from searx.utils import eval_xpath, eval_xpath_list, extract_text
8
9# about
10about = {
11 "website": 'https://www.rottentomatoes.com/',
12 "wikidata_id": 'Q105584',
13 "official_api_documentation": None,
14 "use_official_api": False,
15 "require_api_key": False,
16 "results": 'HTML',
17}
18categories = ['movies']
19
20base_url = "https://www.rottentomatoes.com"
21
22results_xpath = "//search-page-media-row"
23url_xpath = "./a[1]/@href"
24title_xpath = "./a/img/@alt"
25img_src_xpath = "./a/img/@src"
26release_year_xpath = "concat('From ', string(./@releaseyear))"
27score_xpath = "concat('Score: ', string(./@tomatometerscore))"
28cast_xpath = "concat('Starring ', string(./@cast))"
29
30
31def request(query, params):
32 params["url"] = f"{base_url}/search?search={quote_plus(query)}"
33 return params
34
35
36def response(resp):
37 results = []
38
39 dom = html.fromstring(resp.text)
40
41 for result in eval_xpath_list(dom, results_xpath):
42 content = []
43 for xpath in (release_year_xpath, score_xpath, cast_xpath):
44 info = extract_text(eval_xpath(result, xpath))
45
46 # a gap in the end means that no data was found
47 if info and info[-1] != " ":
48 content.append(info)
49
50 results.append(
51 {
52 'url': extract_text(eval_xpath(result, url_xpath)),
53 'title': extract_text(eval_xpath(result, title_xpath)),
54 'content': ', '.join(content),
55 'img_src': extract_text(eval_xpath(result, img_src_xpath)),
56 }
57 )
58
59 return results