how to capture redirected url in python
<p>I have created a page on my site <a href="http://shedez.com/test.html" rel="nofollow">http://shedez.com/test.html</a>  this page redirects the users to a jpg on my server</p>

<p>I want to copy this image to my local drive using a python script.  I want the python script to goto main url first and then get to the destination url of the picture </p>

<p>and than copy the image.  As of now the destination url is hardcoded but in future it will be dynamic, because I will be using geocoding to find the city via ip and then redirect my users to the picture of day from their city.</p>

<p>== my present script ===</p>

<pre><code>import  urllib2, os

req = urllib2.urlopen("http://shedez.com/test.html")

final_link = req.info()
print req.info()

def get_image(remote, local):   
    imgData = urllib2.urlopen(final_link).read()
    output = open(local,'wb')
    output.write(imgData)
    output.close()
    return local

fn = os.path.join(self.tmp, 'bells.jpg')
firstimg = get_image(final_link, fn)
</code></pre>
