How to get final URL after redirection

A

Andreas Perstinger

nishant bhakta said:
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
 
R

Roy Smith

I was only giving an example as bitly, actually i need to proceed with "http://www.mysmartprice.com/out/sen...re=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/B...ativeASIN=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.
 
J

Joel Goldstick

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 wasthe 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/B...ativeASIN=9380349300&linkCode=as2&tag=mysm-21">

in the body, which does kind of the same thing, but in a horrible way. Isuspect they do this provide a hook for the google analytics tracking codein 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.

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
 
D

Denis McMahon

On Sun, Apr 27, 2014 at 8:55 PM, Joel Goldstick
Not visible to me, can you tell me please?

Get some clues about usenet[see below]. Then you'd be able to see his
email address.

[1] Don't use google groups to access usenet messages, use an nntp client
that talks to real newsservers.
[2] Learn not to top post.
[3] See 1, 2.
[4] see [3]
[5] repeat to infinity, referencing previous item each time.

pythonically:

while isUsingGoogleGroups or isTopPosting:
stop_doing_that()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top