From 5169f78a4a9d744a19eb4056c45e98dfbb752836 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Fri, 28 Aug 2020 12:29:31 +0200 Subject: [PATCH] [python] Sample google redirect --- contrib/python/hooks.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/contrib/python/hooks.py b/contrib/python/hooks.py index 415a420f..310a6549 100644 --- a/contrib/python/hooks.py +++ b/contrib/python/hooks.py @@ -24,6 +24,7 @@ quit_hook() -- Clean up before ELinks exits. """ import elinks +from urllib.parse import urlparse, parse_qs from importlib import reload dumbprefixes = { @@ -74,9 +75,12 @@ def follow_url_hook(url): url -- The URL of the link. """ - google_redirect = 'http://www.google.com/url?sa=D&q=' + google_redirect = 'https://www.google.com/url?' if url.startswith(google_redirect): - return url.replace(google_redirect, '') + try: + return parse_qs(urlparse(url).query)['q'][0] + except: + pass def pre_format_html_hook(url, html): """Rewrite the body of a document before it's formatted.