Force using Lynx UA for all searches

This is a possible fix for the recent removal of javascript-free search
results by Google. Forcing the Lynx user agent to be used for all
searches returns search results, although they're formatted a bit
differently than before. If this proves to be a long term fix, styling
can be fixed at a later date.

See #1211
This commit is contained in:
Ben Busby 2025-01-16 16:43:08 -07:00
parent 36d8268643
commit 6f1e1e6847
No known key found for this signature in database
GPG Key ID: B9B7231E01D924A1

View File

@ -18,6 +18,7 @@ AUTOCOMPLETE_URL = ('https://suggestqueries.google.com/'
MOBILE_UA = '{}/5.0 (Android 0; Mobile; rv:54.0) Gecko/54.0 {}/59.0' MOBILE_UA = '{}/5.0 (Android 0; Mobile; rv:54.0) Gecko/54.0 {}/59.0'
DESKTOP_UA = '{}/5.0 (X11; {} x86_64; rv:75.0) Gecko/20100101 {}/75.0' DESKTOP_UA = '{}/5.0 (X11; {} x86_64; rv:75.0) Gecko/20100101 {}/75.0'
LYNX_UA = 'Lynx/2.9.2 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/3.4.0'
# Valid query params # Valid query params
VALID_PARAMS = ['tbs', 'tbm', 'start', 'near', 'source', 'nfpr'] VALID_PARAMS = ['tbs', 'tbm', 'start', 'near', 'source', 'nfpr']
@ -73,6 +74,11 @@ def send_tor_signal(signal: Signal) -> bool:
def gen_user_agent(is_mobile) -> str: def gen_user_agent(is_mobile) -> str:
if True:
# Temporary fix while the removal of javascript-free searches by
# Google is being investigated
return LYNX_UA
user_agent = os.environ.get('WHOOGLE_USER_AGENT', '') user_agent = os.environ.get('WHOOGLE_USER_AGENT', '')
user_agent_mobile = os.environ.get('WHOOGLE_USER_AGENT_MOBILE', '') user_agent_mobile = os.environ.get('WHOOGLE_USER_AGENT_MOBILE', '')
if user_agent and not is_mobile: if user_agent and not is_mobile:
@ -308,7 +314,7 @@ class Request:
now = datetime.now() now = datetime.now()
cookies = { cookies = {
'CONSENT': 'PENDING+987', 'CONSENT': 'PENDING+987',
'SOCS': 'CAESHAgBEhIaAB', 'SOCS': 'CAESHAgBEhIaAB',
} }
# Validate Tor conn and request new identity if the last one failed # Validate Tor conn and request new identity if the last one failed