.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.yahoo_news Namespace Reference

Functions

 request (query, params)
 
 response (resp)
 

Variables

dict about
 
bool language_support = False
 
bool time_range_support = False
 
bool safesearch = False
 
bool paging = True
 
list categories = ['news']
 
tuple search_url
 
 AGO_RE = re.compile(r'([0-9]+)\s*(year|month|week|day|minute|hour)')
 
dict AGO_TIMEDELTA
 

Detailed Description

Yahoo (News)

Yahoo News is "English only" and do not offer localized nor language queries.

Function Documentation

◆ request()

searx.engines.yahoo_news.request ( query,
params )

Definition at line 59 of file yahoo_news.py.

59def request(query, params):
60 offset = (params['pageno'] - 1) * 10 + 1
61
62 params['url'] = search_url.format(offset=offset, query=urlencode({'p': query}))
63 logger.debug("query_url --> %s", params['url'])
64 return params
65
66

◆ response()

searx.engines.yahoo_news.response ( resp)

Definition at line 67 of file yahoo_news.py.

67def response(resp):
68 results = []
69 dom = html.fromstring(resp.text)
70
71 # parse results
72 for result in eval_xpath_list(dom, '//ol[contains(@class,"searchCenterMiddle")]//li'):
73
74 url = eval_xpath_getindex(result, './/h4/a/@href', 0, None)
75 if url is None:
76 continue
77 url = parse_url(url)
78 title = extract_text(result.xpath('.//h4/a'))
79 content = extract_text(result.xpath('.//p'))
80 thumbnail = eval_xpath_getindex(result, './/img/@data-src', 0, None)
81
82 item = {'url': url, 'title': title, 'content': content, 'thumbnail': thumbnail}
83
84 pub_date = extract_text(result.xpath('.//span[contains(@class,"s-time")]'))
85 ago = AGO_RE.search(pub_date)
86 if ago:
87 number = int(ago.group(1))
88 delta = AGO_TIMEDELTA[ago.group(2)]
89 pub_date = datetime.now() - delta * number
90 else:
91 try:
92 pub_date = parser.parse(pub_date)
93 except parser.ParserError:
94 pub_date = None
95
96 if pub_date is not None:
97 item['publishedDate'] = pub_date
98 results.append(item)
99
100 for suggestion in eval_xpath_list(dom, '//div[contains(@class,"AlsoTry")]//td'):
101 results.append({'suggestion': extract_text(suggestion)})
102
103 return results

Variable Documentation

◆ about

dict searx.engines.yahoo_news.about
Initial value:
1= {
2 "website": 'https://news.yahoo.com',
3 "wikidata_id": 'Q3044717',
4 "official_api_documentation": 'https://developer.yahoo.com/api/',
5 "use_official_api": False,
6 "require_api_key": False,
7 "results": 'HTML',
8}

Definition at line 25 of file yahoo_news.py.

◆ AGO_RE

searx.engines.yahoo_news.AGO_RE = re.compile(r'([0-9]+)\s*(year|month|week|day|minute|hour)')

Definition at line 48 of file yahoo_news.py.

◆ AGO_TIMEDELTA

dict searx.engines.yahoo_news.AGO_TIMEDELTA
Initial value:
1= {
2 'minute': timedelta(minutes=1),
3 'hour': timedelta(hours=1),
4 'day': timedelta(days=1),
5 'week': timedelta(days=7),
6 'month': timedelta(days=30),
7 'year': timedelta(days=365),
8}

Definition at line 49 of file yahoo_news.py.

◆ categories

list searx.engines.yahoo_news.categories = ['news']

Definition at line 38 of file yahoo_news.py.

◆ language_support

bool searx.engines.yahoo_news.language_support = False

Definition at line 34 of file yahoo_news.py.

◆ paging

bool searx.engines.yahoo_news.paging = True

Definition at line 37 of file yahoo_news.py.

◆ safesearch

bool searx.engines.yahoo_news.safesearch = False

Definition at line 36 of file yahoo_news.py.

◆ search_url

tuple searx.engines.yahoo_news.search_url
Initial value:
1= (
2 # fmt: off
3 'https://news.search.yahoo.com/search'
4 '?{query}&b={offset}'
5 # fmt: on
6)

Definition at line 41 of file yahoo_news.py.

◆ time_range_support

bool searx.engines.yahoo_news.time_range_support = False

Definition at line 35 of file yahoo_news.py.