Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.029 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'append': 0.09; 'http': 0.09; 'parameter': 0.09; 'subject:How': 0.10; 'cc:addr:python- list': 0.11; 'handler.': 0.16; 'headers.': 0.16; 'landing': 0.16; 'roy': 0.16; 'subject:URL': 0.16; 'subject:after': 0.16; 'url.': 0.16; 'url:creative': 0.16; 'url:tag': 0.16; 'thursday,': 0.16; ':-)': 0.16; 'wrote:': 0.18; 'library': 0.18; 'thu,': 0.19; 'code,': 0.22; 'example': 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; 'environment': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'asking': 0.27; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; "doesn't": 0.30; 'url:gp': 0.30; 'message- id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'code': 0.31; 'requests': 0.31; "skip:' 10": 0.31; 'that.': 0.31; 'url:category': 0.31; 'url:python': 0.33; 'proceed': 0.33; 'something': 0.35; 'case,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'google': 0.35; 'really': 0.36; 'url:ie': 0.36; 'url:ref': 0.36; 'done': 0.36; 'url:listinfo': 0.36; 'similar': 0.36; 'url:org': 0.36; 'question,': 0.38; 'url:amazon': 0.38; 'pm,': 0.38; 'does': 0.39; 'url:mail': 0.40; 'helps': 0.61; 'include:': 0.61; 'location:': 0.61; 'tracking': 0.61; 'full': 0.61; "you're": 0.61; 'kind': 0.63; 'provide': 0.64; 'details': 0.65; 'smith': 0.68; 'subject:get': 0.81; 'horrible': 0.84; 'url:php': 0.85; 'joel': 0.91; 'thing,': 0.91; 'url:latest': 0.91; 'examine': 0.93; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=B6DtS2ID22YeAfoJUWUzw5wB9QNtUv+e1Ws5mfqUhfs=; b=nre1UknCGTXT9uyZQwRniBeHg8qZj5fOXvkuRRNfm3h1OOF5o3+vhufKtGl3mhdxF5 Ph3ZgTo1TqE/2NUtcTCcMZ9WM8VYQuFy7Sl/T9iaNGaTi9gumzlKmz9hIVqBTCAFQBxD jODo5R/oWdgQeQepuzmuPACbmrwCuYN630LpFWFXmURrkcJ+Fg3DfLu+gv48TZ2GLPYS bPZLutsFENynGCUhRRKRIxm3NMIKZtRBB8b7MOytoOKOPC3mmZFVmqixYV/qrnoiKhQv DjB9UXRoT5N7vrEetCyAJOxEgm14ckK21XyTZebcn3jwi3gGyncAfyT5mLwkWUrp9QGS RolQ== MIME-Version: 1.0 X-Received: by 10.58.226.233 with SMTP id rv9mr383360vec.56.1383244980931; Thu, 31 Oct 2013 11:43:00 -0700 (PDT) In-Reply-To: References: Date: Thu, 31 Oct 2013 14:43:00 -0400 Subject: Re: How to get final URL after redirection From: Joel Goldstick To: Roy Smith Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: "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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1383244990 news.xs4all.nl 15922 [2001:888:2000:d::a6]:47878 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:58202 On Thu, Oct 31, 2013 at 2:33 PM, Roy Smith wrote: > On Thursday, October 31, 2013 2:10:35 PM UTC-4, nishant bhakta wrote: > >> I was only giving an example as bitly, actually i need to proceed with "= http://www.mysmartprice.com/out/sendtostore.php?id=3D107120529&top_category= =3Delectronics&store=3Damazon&mspid=3D51889&category=3Dcomputer&rk=3D30" th= is is the link that landed at "www.amazong.com" and i want write code that = take this link and append something to the final landing link that is "www.= amazon.com" > > When asking a question, it really helps to ask the question you want to a= sk, not some other question which you think is similar :-) Details matter. > > The "normal" way a redirect is done is to return a 301 (or 302) status co= de, 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: > > > > 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 an= d 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 --=20 Joel Goldstick http://joelgoldstick.com