71 """Google-News search request"""
73 sxng_locale = params.get(
'searxng_locale',
'en-US')
74 ceid = locales.get_engine_locale(sxng_locale, traits.custom[
'ceid'], default=
'US:en')
75 google_info = get_google_info(params, traits)
76 google_info[
'subdomain'] =
'news.google.com'
78 ceid_region, ceid_lang = ceid.split(
':')
79 ceid_lang, ceid_suffix = (
86 google_info[
'params'][
'hl'] = ceid_lang
88 if ceid_suffix
and ceid_suffix
not in [
'Hans',
'Hant']:
90 if ceid_region.lower() == ceid_lang:
91 google_info[
'params'][
'hl'] = ceid_lang +
'-' + ceid_region
93 google_info[
'params'][
'hl'] = ceid_lang +
'-' + ceid_suffix
95 elif ceid_region.lower() != ceid_lang:
97 if ceid_region
in [
'AT',
'BE',
'CH',
'IL',
'SA',
'IN',
'BD',
'PT']:
98 google_info[
'params'][
'hl'] = ceid_lang
100 google_info[
'params'][
'hl'] = ceid_lang +
'-' + ceid_region
102 google_info[
'params'][
'lr'] =
'lang_' + ceid_lang.split(
'-')[0]
103 google_info[
'params'][
'gl'] = ceid_region
107 + google_info[
'subdomain']
112 **google_info[
'params'],
116 + (
'&ceid=%s' % ceid)
119 params[
'url'] = query_url
120 params[
'cookies'] = google_info[
'cookies']
121 params[
'headers'].update(google_info[
'headers'])
126 """Get response from google's search request"""
128 detect_google_sorry(resp)
131 dom = html.fromstring(resp.text)
133 for result
in eval_xpath_list(dom,
'//div[@class="xrnccd"]'):
139 href = eval_xpath_getindex(result,
'./article/a/@href', 0)
140 href = href.split(
'?')[0]
141 href = href.split(
'/')[-1]
142 href = base64.urlsafe_b64decode(href +
'====')
143 href = href[href.index(b
'http') :].split(b
'\xd2')[0]
146 title = extract_text(eval_xpath(result,
'./article/h3[1]'))
150 pub_date = extract_text(eval_xpath(result,
'./article//time'))
151 pub_origin = extract_text(eval_xpath(result,
'./article//a[@data-n-tid]'))
153 content =
' / '.join([x
for x
in [pub_origin, pub_date]
if x])
159 thumbnail = extract_text(result.xpath(
'preceding-sibling::a/figure/img/@src'))
166 'thumbnail': thumbnail,
274 _fetch_traits(engine_traits, add_domains=
False)
276 engine_traits.custom[
'ceid'] = {}
278 for ceid
in ceid_list:
279 if ceid
in _skip_values:
282 region, lang = ceid.split(
':')
285 if x[1]
not in [
'Hant',
'Hans']:
288 sxng_locale = _ceid_locale_map.get(ceid, lang +
'-' + region)
290 locale = babel.Locale.parse(sxng_locale, sep=
'-')
291 except babel.UnknownLocaleError:
292 print(
"ERROR: %s -> %s is unknown by babel" % (ceid, sxng_locale))
295 engine_traits.custom[
'ceid'][locales.region_tag(locale)] = ceid