0

I'm using the following code to get the redirect URL.

req = urllib2.Request(url_str, headers=hdrs)
real_url = urllib2.urlopen(req).geturl()

For example, if I set url_str = 'http://wearfigs.com' and run the code, then I end up getting real_url = 'http://www.figsscrubs.com', which is what I want, because in the browser, wearfigs.com redirects to figsscrubs.com.

However, when I try the same process with url_str set to http://www.greenforestry.us, the real_url it gives me is exactly the same, even though the browser redirects to http://www.greenforestry.us/GreenForestry.us/Welcome.html. Same netloc, different path. I want to get the final redirect URL in every case, including when the netloc is the same and the path is different, like in the above example, but geturl() isn't doing the trick. Is there a way?

Tyler
  • 2,579
  • 2
  • 22
  • 32
  • 3
    http://www.greenforestry.us doesn't redirect, it uses an HTML `meta http-equiv="refresh"`. – Pavel Anossov Jun 20 '13 at 21:43
  • Ah, got it. Here's what I was looking for: http://stackoverflow.com/questions/2318446/how-to-follow-meta-refreshes-in-python – Tyler Jun 20 '13 at 22:44

0 Answers0