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


Groups > comp.lang.python > #58203

Re: How to get final URL after redirection

Path csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <roy@panix.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.018
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'back.': 0.09; 'http': 0.09; 'parameter': 0.09; 'subject:How': 0.10; 'cc:addr:python- list': 0.11; 'handler.': 0.16; 'headers.': 0.16; 'received:166.84': 0.16; 'received:166.84.1': 0.16; 'received:166.84.1.89': 0.16; 'received:24.136': 0.16; 'received:mailbackend.panix.com': 0.16; 'received:panix.com': 0.16; 'roy': 0.16; 'subject:URL': 0.16; 'subject:after': 0.16; 'url.': 0.16; 'url:creative': 0.16; 'url:tag': 0.16; 'used).': 0.16; 'wrote:': 0.18; 'library': 0.18; 'mechanism': 0.19; 'received:166': 0.19; 'code,': 0.22; 'cc:addr:python.org': 0.22; '31,': 0.24; 'body,': 0.24; 'headers': 0.24; 'url:utf8': 0.24; "haven't": 0.24; 'looks': 0.24; '(or': 0.24; '---': 0.24; 'environment': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'received:24': 0.27; 'tried': 0.27; "doesn't": 0.30; 'url:gp': 0.30; 'url:mailman': 0.30; '(which': 0.31; 'code': 0.31; 'requests': 0.31; "skip:' 10": 0.31; 'that.': 0.31; 'url:python': 0.33; "can't": 0.35; 'case,': 0.35; 'but': 0.35; 'google': 0.35; 'described': 0.36; 'url:ie': 0.36; 'url:ref': 0.36; 'done': 0.36; 'url:listinfo': 0.36; 'charset:us-ascii': 0.36; 'url:org': 0.36; 'url:amazon': 0.38; 'pm,': 0.38; 'anything': 0.39; 'does': 0.39; 'url:mail': 0.40; 'include:': 0.61; 'location:': 0.61; 'tracking': 0.61; 'full': 0.61; "you're": 0.61; 'header:Message-Id:1': 0.63; 'kind': 0.63; 'provide': 0.64; 'to:addr:gmail.com': 0.65; 'smith': 0.68; 'subject:get': 0.81; 'email addr:panix.com': 0.84; 'horrible': 0.84; '2013,': 0.91; 'joel': 0.91; 'thing,': 0.91; 'url:latest': 0.91; 'examine': 0.93; 'imagine': 0.93
Subject Re: How to get final URL after redirection
Mime-Version 1.0 (Apple Message framework v1283)
Content-Type text/plain; charset=us-ascii
From Roy Smith <roy@panix.com>
In-Reply-To <CAPM-O+ygJvWtsW-Lsk4+O5sfz_ycxRPWqt+xWUt8CcBEDAKGFQ@mail.gmail.com>
Date Thu, 31 Oct 2013 14:50:07 -0400
Content-Transfer-Encoding quoted-printable
References <d728b722-d978-4f94-b053-e0374a09ffbb@googlegroups.com> <mailman.1887.1383242269.18130.python-list@python.org> <d6745f8b-ff1a-4b06-958d-e34f75304fd6@googlegroups.com> <db178cf8-2cf7-4cbb-b13a-2f60f2be2b87@googlegroups.com> <CAPM-O+ygJvWtsW-Lsk4+O5sfz_ycxRPWqt+xWUt8CcBEDAKGFQ@mail.gmail.com>
To Joel Goldstick <joel.goldstick@gmail.com>
X-Mailer Apple Mail (2.1283)
Cc "python-list@python.org" <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1889.1383245410.18130.python-list@python.org> (permalink)
Lines 38
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1383245410 news.xs4all.nl 16007 [2001:888:2000:d::a6]:51129
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:58203

Show key headers only | View raw


On Oct 31, 2013, at 2:43 PM, Joel Goldstick wrote:

>> The "normal" way a redirect is done is to return a 301 (or 302) status code, and include a Location: line in the HTTP response headers.  If that was the case, you would just do a GET on the url with a library like requests and examine the status code and headers in the response object you got back.
>> 
>> This URL, however, doesn't do that.  What it does do is include:
>> 
>> <meta http-equiv="Refresh"  content="0; url=http://amazon.in/gp/offer-listing/B00AF856T2/?/ref=as_li_tf_tl?ie=UTF8&camp=3626&creative=24790&creativeASIN=9380349300&linkCode=as2&tag=mysm-21">
>> 
>> in the body, which does kind of the same thing, but in a horrible way.  I suspect they do this provide a hook for the google analytics tracking code in the window.onload handler.  Unless you wanted to include a full HTML and javascript execution environment in your application, you're pretty much toast here.
>> --
>> https://mail.python.org/mailman/listinfo/python-list
> 
> You might look at the requests module:
> http://www.python-requests.org/en/latest/api/
> 
> It has an 'allow_redirects' parameter that looks like you can set to
> get the final url.  Haven't tried it


I can't imagine this does anything other than the 30x processing described above (which won't work in the OP's case because that's not the mechanism used).

---
Roy Smith
roy@panix.com

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


Thread

How to get final URL after redirection nishant bhakta <bhaktanishant@gmail.com> - 2013-10-31 09:17 -0700
  Re: How to get final URL after redirection Andreas Perstinger <andipersti@gmail.com> - 2013-10-31 18:42 +0100
    Re: How to get final URL after redirection nishant bhakta <bhaktanishant@gmail.com> - 2013-10-31 11:10 -0700
      Re: How to get final URL after redirection Roy Smith <roy@panix.com> - 2013-10-31 11:33 -0700
        Re: How to get final URL after redirection Joel Goldstick <joel.goldstick@gmail.com> - 2013-10-31 14:43 -0400
        Re: How to get final URL after redirection Roy Smith <roy@panix.com> - 2013-10-31 14:50 -0400

csiph-web