Re: No more Redirect page.
Lawrence D’Oliveiro <[email protected]> Sat, 25 Jul 2026 04:33:42 -0000 (UTC)
| Newsgroups | comp.lang.python,alt.comp.software.firefox |
|---|---|
| Organization | A noiseless patient Spider |
| Message-ID | <[email protected]> |
On Fri, 24 Jul 2026 11:03:09 -0400, micky wrote:
> You may have noticed by now that clicking on Google search links
> sometimes or always makes you stop at a page to "permit" redirection
> to another page, even though you clicked on it in the first place
> and even though it never did this before. "The "redirect notice"
> page usually appears because Google wraps outbound links with a
> tracking parameter (google.com/url) to gather analytics and scan for
> malicious URLs".
I often copy and paste links into the following script for this reason.
Feel free to experiment with this as appropriate. Note the “--unquote”
option, because sometimes I find the wrapped URL has an extra
(needless) level of quoting.
----
#!/usr/bin/python3
#+
# Given a URL from various sites that like to include redirection
# capture cruft, extract the URL and discard the cruft.
#-
import sys
import re
from urllib import \
parse as urlparse
import getopt
start_marker = r"\=(https?(\:\/\/|\%3a\%2f\%2f))"
show_original = False
force_unquote = False
opts, args = getopt.getopt \
(
sys.argv[1:],
"",
["original", "unquote"]
)
for keyword, value in opts :
if keyword == "--original" :
show_original = True
elif keyword == "--unquote" :
force_unquote = True
#end if
#end for
urls = args
if len(urls) == 0 :
raise getopt.GetoptError("pass at least one URL to unredirect")
#end if
for url in urls :
matches = list(re.compile(start_marker, re.IGNORECASE).finditer(url))
if len(matches) != 0 :
match = matches[-1]
startpos = match.start(1)
endpos = url.find("&", match.end(1))
if endpos < 0 :
endpos = len(url)
#end if
actual = url[startpos : endpos]
if match.group(2).startswith("%") or force_unquote :
actual = urlparse.unquote(actual)
#end if
if show_original :
sys.stdout.write("%s => " % url)
#end if
sys.stdout.write("%s\n" % actual)
else :
sys.stdout.write("# Cannot understand: %s\n" % url)
#end if
#end for