146 """Build Yahoo search request."""
148 lang, region = (params[
"language"].split(
"-") + [
None])[:2]
149 lang = yahoo_languages.get(lang,
"any")
157 url_params = {
'p': query}
159 btf = time_range_dict.get(params[
'time_range'])
161 url_params[
'btf'] = btf
163 if params[
'pageno'] == 1:
164 url_params[
'iscqry'] =
''
165 elif params[
'pageno'] >= 2:
166 url_params[
'b'] = params[
'pageno'] * 7 + 1
168 url_params[
'bct'] = 0
169 url_params[
'xargs'] = 0
177 'vm': safesearch_dict[params[
'safesearch']],
179 'vl': f
'lang_{lang}',
187 domain = region2domain.get(region)
189 domain = lang2domain.get(lang, f
'{lang}.search.yahoo.com')
190 logger.debug(f
'domain selected: {domain}')
191 logger.debug(f
'cookies: {params["cookies"]}')
193 params[
'url'] = f
'https://{domain}/search?{urlencode(url_params)}'
194 params[
'domain'] = domain
220 dom = html.fromstring(resp.text)
222 url_xpath =
'.//div[contains(@class,"compTitle")]/h3/a/@href'
223 title_xpath =
'.//h3//a/@aria-label'
225 domain = resp.search_params[
'domain']
226 if domain ==
"search.yahoo.com":
227 url_xpath =
'.//div[contains(@class,"compTitle")]/a/@href'
228 title_xpath =
'.//div[contains(@class,"compTitle")]/a/h3/span'
231 for result
in eval_xpath_list(dom,
'//div[contains(@class,"algo-sr")]'):
232 url = eval_xpath_getindex(result, url_xpath, 0, default=
None)
237 title = eval_xpath_getindex(result, title_xpath, 0, default=
'')
238 title: str = extract_text(title)
239 content = eval_xpath_getindex(result,
'.//div[contains(@class, "compText")]', 0, default=
'')
240 content: str = extract_text(content, allow_none=
True)
248 'title':
" ".join(html_to_text(title).strip().split()),
249 'content':
" ".join(html_to_text(content).strip().split()),
253 for suggestion
in eval_xpath_list(dom,
'//div[contains(@class, "AlsoTry")]//table//a'):
255 results.append({
'suggestion': extract_text(suggestion)})