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


Groups > comp.lang.python > #58192 > unrolled thread

How to get final URL after redirection

Started bynishant bhakta <bhaktanishant@gmail.com>
First post2013-10-31 09:17 -0700
Last post2013-10-31 14:50 -0400
Articles 6 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  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

#58192 — How to get final URL after redirection

Fromnishant bhakta <bhaktanishant@gmail.com>
Date2013-10-31 09:17 -0700
SubjectHow to get final URL after redirection
Message-ID<d728b722-d978-4f94-b053-e0374a09ffbb@googlegroups.com>
I have a link that will redirect to any-other link and i have to work with that final link.
For example if i have a link "www.bit.ly/2V6CFi" that will redirect to "www.google.com".
Here i want that i take "www.bit.ly/2V6CFi" and find the final redirect link and append "#q=python" to that link and produce an output that is "www.google.com/#q=python".

[toc] | [next] | [standalone]


#58198

FromAndreas Perstinger <andipersti@gmail.com>
Date2013-10-31 18:42 +0100
Message-ID<mailman.1887.1383242269.18130.python-list@python.org>
In reply to#58192
nishant bhakta <bhaktanishant@gmail.com> wrote:

>I have a link that will redirect to any-other link and i have to work
>with that final link. For example if i have a link "www.bit.ly/2V6CFi"
>that will redirect to "www.google.com". Here i want that i take
>"www.bit.ly/2V6CFi" and find the final redirect link and append
>"#q=python" to that link and produce an output that is
>"www.google.com/#q=python".

For bitly links you need to use their API:
http://dev.bitly.com/links.html#v3_expand

There is a python module for interacting with it:
https://github.com/bitly/bitly-api-python

Bye, Andreas

[toc] | [prev] | [next] | [standalone]


#58200

Fromnishant bhakta <bhaktanishant@gmail.com>
Date2013-10-31 11:10 -0700
Message-ID<d6745f8b-ff1a-4b06-958d-e34f75304fd6@googlegroups.com>
In reply to#58198
> There is a python module for interacting with it:
> 
> https://github.com/bitly/bitly-api-python
> 
> 
> 
> Bye, Andreas

I was only giving an example as bitly, actually i need to proceed with "http://www.mysmartprice.com/out/sendtostore.php?id=107120529&top_category=electronics&store=amazon&mspid=51889&category=computer&rk=30" this 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"

[toc] | [prev] | [next] | [standalone]


#58201

FromRoy Smith <roy@panix.com>
Date2013-10-31 11:33 -0700
Message-ID<db178cf8-2cf7-4cbb-b13a-2f60f2be2b87@googlegroups.com>
In reply to#58200
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=107120529&top_category=electronics&store=amazon&mspid=51889&category=computer&rk=30" this 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 ask, 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 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.

[toc] | [prev] | [next] | [standalone]


#58202

FromJoel Goldstick <joel.goldstick@gmail.com>
Date2013-10-31 14:43 -0400
Message-ID<mailman.1888.1383244990.18130.python-list@python.org>
In reply to#58201
On Thu, Oct 31, 2013 at 2:33 PM, Roy Smith <roy@panix.com> 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=107120529&top_category=electronics&store=amazon&mspid=51889&category=computer&rk=30" this 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 ask, 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 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

-- 
Joel Goldstick
http://joelgoldstick.com

[toc] | [prev] | [next] | [standalone]


#58203

FromRoy Smith <roy@panix.com>
Date2013-10-31 14:50 -0400
Message-ID<mailman.1889.1383245410.18130.python-list@python.org>
In reply to#58201
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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web