155 """Build Yahoo search request."""
157 lang, region = (params[
"language"].split(
"-") + [
None])[:2]
158 lang = yahoo_languages.get(lang,
"any")
166 url_params = {
'p': query}
168 btf = time_range_dict.get(params[
'time_range'])
170 url_params[
'btf'] = btf
172 if params[
'pageno'] == 1:
173 url_params[
'iscqry'] =
''
174 elif params[
'pageno'] >= 2:
175 url_params[
'b'] = params[
'pageno'] * 7 + 1
177 url_params[
'bct'] = 0
178 url_params[
'xargs'] = 0
186 'vm': safesearch_dict[params[
'safesearch']],
188 'vl': f
'lang_{lang}',
196 domain = region2domain.get(region)
198 domain = lang2domain.get(lang, f
'{lang}.search.yahoo.com')
199 logger.debug(f
'domain selected: {domain}')
200 logger.debug(f
'cookies: {params["cookies"]}')
202 params[
'url'] = f
'https://{domain}/search?{urlencode(url_params)}'
203 params[
'domain'] = domain
229 dom = html.fromstring(resp.text)
231 url_xpath =
'.//div[contains(@class,"compTitle")]/h3/a/@href'
232 title_xpath =
'.//h3//a/@aria-label'
234 domain = resp.search_params[
'domain']
235 if domain ==
"search.yahoo.com":
236 url_xpath =
'.//div[contains(@class,"compTitle")]/a/@href'
237 title_xpath =
'.//div[contains(@class,"compTitle")]/a/h3/span'
240 for result
in eval_xpath_list(dom,
'//div[contains(@class,"algo-sr")]'):
241 url = eval_xpath_getindex(result, url_xpath, 0, default=
None)
246 title = eval_xpath_getindex(result, title_xpath, 0, default=
'')
247 title: str = extract_text(title)
248 content = eval_xpath_getindex(result,
'.//div[contains(@class, "compText")]', 0, default=
'')
249 content: str = extract_text(content, allow_none=
True)
257 'title':
" ".join(html_to_text(title).strip().split()),
258 'content':
" ".join(html_to_text(content).strip().split()),
262 for suggestion
in eval_xpath_list(dom,
'//div[contains(@class, "AlsoTry")]//table//a'):
264 results.append({
'suggestion': extract_text(suggestion)})