Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #197825

Re: No more Redirect page.

From Lawrence D’Oliveiro <ldo@nz.invalid>
Newsgroups comp.lang.python, alt.comp.software.firefox
Subject Re: No more Redirect page.
Date 2026-07-25 04:33 +0000
Organization A noiseless patient Spider
Message-ID <1141eb5$16llq$1@dont-email.me> (permalink)
References <p9v66l1ltn55trg0vccg1cj83jcpm89mu1@4ax.com>

Cross-posted to 2 groups.

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Re: No more Redirect page. Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-07-25 04:33 +0000
  Re: No more Redirect page. Gilmeh Serda <gilmeh.serda@nothing.here.invalid> - 2026-07-25 15:59 +0000
    Re: No more Redirect page. ram@zedat.fu-berlin.de (Stefan Ram) - 2026-07-25 16:24 +0000
      Re: No more Redirect page. Gilmeh Serda <gilmeh.serda@nothing.here.invalid> - 2026-07-26 18:32 +0000
    Re: No more Redirect page. Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-07-29 23:36 +0000
      Re: No more Redirect page. Jon Ribbens <jon+usenet@unequivocal.eu> - 2026-07-29 23:45 +0000

csiph-web