[feat] engines: add google cse engine (#6364)

Adds a new google cse engine as an alternative to the currently broken html
google engine.

It works by generating a token which is cached for 1 hour and it only uses the
public CSE id from blackle.com.  We do have two others but I think just
hardcoding one will be enough.

Will be broken in 2027 due to google deprecating it but I it will be good while
it lasts.

I found I can get up to 20 results per page. Setting safesearch and language
works and I just copied the traits from the google engine.

Also set old google engine as inactive as it is completely broken for now.
This commit is contained in:
vojkovic
2026-07-04 11:58:28 +00:00
committed by Markus Heiser
parent 747cec4c23
commit 1cdf01a719
4 changed files with 172 additions and 5 deletions

View File

@@ -32,7 +32,7 @@ from searx.utils import (
eval_xpath_getindex,
eval_xpath_list,
extract_text,
gen_gsa_useragent,
# gen_gsa_useragent,
)
if t.TYPE_CHECKING:
@@ -197,7 +197,7 @@ def get_google_info(params: "OnlineParams", eng_traits: EngineTraits) -> dict[st
# https://developers.google.com/custom-search/docs/xml_results_appendices#interfaceLanguages
# https://github.com/searxng/searxng/issues/2515#issuecomment-1607150817
ret_val["params"]["hl"] = f"{lang_code}-{country}"
ret_val["params"]["hl"] = f"{lang_code}"
# lr parameter:
# The lr (language restrict) parameter restricts search results to
@@ -268,7 +268,11 @@ def get_google_info(params: "OnlineParams", eng_traits: EngineTraits) -> dict[st
# HTTP headers
ret_val["headers"]["Accept"] = "*/*"
ret_val["headers"]["User-Agent"] = gen_gsa_useragent()
# GSA for iPhone useragent had been added in
# - https://github.com/searxng/searxng/pull/5644
# but doe no longer work
# - https://github.com/searxng/searxng/issues/6359
# ret_val["headers"]["User-Agent"] = gen_gsa_useragent()
# Cookies