• Re: No more Redirect page.

    From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@ldo@nz.invalid to comp.lang.python,alt.comp.software.firefox on Sat Jul 25 04:33:42 2026
    From Newsgroup: comp.lang.python

    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 rCL--unquoterCY 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
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Gilmeh Serda@gilmeh.serda@nothing.here.invalid to comp.lang.python,alt.comp.software.firefox on Sat Jul 25 15:59:03 2026
    From Newsgroup: comp.lang.python

    On Sat, 25 Jul 2026 04:33:42 -0000 (UTC), Lawrence DrCOOliveiro wrote:

    I often copy and paste links into the following script for this reason.

    Why not use pyperclip? Then you can just use clipboard:

    1. Copy original URL
    2. Run script (+ options)
    3. Paste resulting URL

    https://pypi.org/project/pyperclip/

    You may also want to read this: https://github.com/asweigart/pyperclip/blob/master/src/pyperclip/
    __init__.py row 19.


    If there are only a few options you might even wanna create an alias for
    each version, like scra and scrb or something and put it in your .bashrc:

    alias scra='scriptname -option1';
    alias scrb='scriptname -option2';

    Your use of shebang suggests *nix, so...


    If I think ArgumentParser is too bulky for a small script, I usually just
    use sys module, which you already have imported.

    def main(opt):
    URL = pyperclip.paste()

    if opt == 1:
    [...]
    elif opt == 2:
    [...]

    pyperclip.copy(resulting_URL)

    if __name__ == '__main__':
    args = sys.argv[1:]
    if '-option1' in args:
    main(1)
    elif '-option2' in args:
    main(2)
    else:
    print(usage)

    But each to their own... It's your script.
    --
    Gilmeh

    Everybody likes a kidder, but nobody lends him money. -- Arthur Miller
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From ram@ram@zedat.fu-berlin.de (Stefan Ram) to comp.lang.python,alt.comp.software.firefox on Sat Jul 25 16:24:37 2026
    From Newsgroup: comp.lang.python

    Gilmeh Serda <gilmeh.serda@nothing.here.invalid> wrote or quoted:
    URL = pyperclip.paste()

    I read from the clipboard all the time, but prefer to
    use the standard library, so I,

    import tkinter as tk
    . . .
    content = tk.Tk().clipboard_get()

    .


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Gilmeh Serda@gilmeh.serda@nothing.here.invalid to comp.lang.python,alt.comp.software.firefox on Sun Jul 26 18:32:03 2026
    From Newsgroup: comp.lang.python

    On 25 Jul 2026 16:24:37 GMT, Stefan Ram wrote:

    I read from the clipboard all the time, but prefer to
    use the standard library, so I,

    You do you.
    --
    Gilmeh

    This is the theory that Jack built. This is the flaw that lay in the
    theory that Jack built. This is the palpable verbal haze that hid the flaw that lay in...
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@ldo@nz.invalid to comp.lang.python,alt.comp.software.firefox on Wed Jul 29 23:36:45 2026
    From Newsgroup: comp.lang.python

    On Sat, 25 Jul 2026 15:59:03 GMT, Gilmeh Serda wrote:

    On Sat, 25 Jul 2026 04:33:42 -0000 (UTC), Lawrence DrCOOliveiro wrote:

    I often copy and paste links into the following script for this
    reason.

    Why not use pyperclip? Then you can just use clipboard:

    And then have to install a bunch of extra dependencies. My existing
    script relies on nothing other than the standard Python library:

    import sys
    import re
    from urllib import \
    parse as urlparse
    import getopt

    ThatrCOs it.
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Jon Ribbens@jon+usenet@unequivocal.eu to comp.lang.python on Wed Jul 29 23:45:23 2026
    From Newsgroup: comp.lang.python

    On 2026-07-29, Lawrence DrCOOliveiro <ldo@nz.invalid> wrote:
    On Sat, 25 Jul 2026 15:59:03 GMT, Gilmeh Serda wrote:
    On Sat, 25 Jul 2026 04:33:42 -0000 (UTC), Lawrence DrCOOliveiro wrote:
    I often copy and paste links into the following script for this
    reason.

    Why not use pyperclip? Then you can just use clipboard:

    And then have to install a bunch of extra dependencies. My existing
    script relies on nothing other than the standard Python library:

    import sys
    import re
    from urllib import \
    parse as urlparse
    import getopt

    ThatrCOs it.

    That's a bonus it's true, but the whole '\' business gives me conniptions.
    --- Synchronet 3.22a-Linux NewsLink 1.2