80 """Google-News search request"""
82 sxng_locale = params.get(
'searxng_locale',
'en-US')
83 ceid = locales.get_engine_locale(sxng_locale, traits.custom[
'ceid'], default=
'US:en')
84 google_info = get_google_info(params, traits)
85 google_info[
'subdomain'] =
'news.google.com'
87 ceid_region, ceid_lang = ceid.split(
':')
88 ceid_lang, ceid_suffix = (
95 google_info[
'params'][
'hl'] = ceid_lang
97 if ceid_suffix
and ceid_suffix
not in [
'Hans',
'Hant']:
99 if ceid_region.lower() == ceid_lang:
100 google_info[
'params'][
'hl'] = ceid_lang +
'-' + ceid_region
102 google_info[
'params'][
'hl'] = ceid_lang +
'-' + ceid_suffix
104 elif ceid_region.lower() != ceid_lang:
106 if ceid_region
in [
'AT',
'BE',
'CH',
'IL',
'SA',
'IN',
'BD',
'PT']:
107 google_info[
'params'][
'hl'] = ceid_lang
109 google_info[
'params'][
'hl'] = ceid_lang +
'-' + ceid_region
111 google_info[
'params'][
'lr'] =
'lang_' + ceid_lang.split(
'-')[0]
112 google_info[
'params'][
'gl'] = ceid_region
116 + google_info[
'subdomain']
121 **google_info[
'params'],
125 + (
'&ceid=%s' % ceid)
128 params[
'url'] = query_url
129 params[
'cookies'] = google_info[
'cookies']
130 params[
'headers'].update(google_info[
'headers'])
135 """Get response from google's search request"""
137 detect_google_sorry(resp)
140 dom = html.fromstring(resp.text)
142 for result
in eval_xpath_list(dom,
'//div[@class="xrnccd"]'):
148 href = eval_xpath_getindex(result,
'./article/a/@href', 0)
149 href = href.split(
'?')[0]
150 href = href.split(
'/')[-1]
151 href = base64.urlsafe_b64decode(href +
'====')
152 href = href[href.index(b
'http') :].split(b
'\xd2')[0]
155 title = extract_text(eval_xpath(result,
'./article/h3[1]'))
159 pub_date = extract_text(eval_xpath(result,
'./article//time'))
160 pub_origin = extract_text(eval_xpath(result,
'./article//a[@data-n-tid]'))
162 content =
' / '.join([x
for x
in [pub_origin, pub_date]
if x])
168 thumbnail = extract_text(result.xpath(
'preceding-sibling::a/figure/img/@src'))
175 'thumbnail': thumbnail,
283 _fetch_traits(engine_traits, add_domains=
False)
285 engine_traits.custom[
'ceid'] = {}
287 for ceid
in ceid_list:
288 if ceid
in _skip_values:
291 region, lang = ceid.split(
':')
294 if x[1]
not in [
'Hant',
'Hans']:
297 sxng_locale = _ceid_locale_map.get(ceid, lang +
'-' + region)
299 locale = babel.Locale.parse(sxng_locale, sep=
'-')
300 except babel.UnknownLocaleError:
301 print(
"ERROR: %s -> %s is unknown by babel" % (ceid, sxng_locale))
304 engine_traits.custom[
'ceid'][locales.region_tag(locale)] = ceid