How to make download manager more robust?
<p>I have made this simple download manager, but the problem is it wont work on complex urls, when pages are redirected.</p>

<pre><code>def str(d):
    for i in range(len(d)):
        if d[-i] == '/':
            x=-i
            break
    s=[]
    l=len(d)+x+1
    print d[l],d[len(d)-1]

    s=d[l:]


    return s

import urllib2
url=raw_input()
filename=str(url)
webfile = urllib2.urlopen(url)
data = webfile.read()
fout =open(filename,"w")
fout.write(data)
fout.close()
webfile.close()
</code></pre>

<p>it wouldn't work for <a href="http://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=9&amp;ved=0CG0QFjAI&amp;url=http%3A%2F%2Fwww.iasted.org%2Fconferences%2Fformatting%2FPresentations-Tips.ppt&amp;ei=clfWTpjZEIblrAfC8qWXDg&amp;usg=AFQjCNEIgqx6x4ULHFXzzYDzCITuUJOczA&amp;sig2=0VtKXPvoDnIq-lIR4S9LEQ" rel="nofollow">http://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=9&amp;ved=0CG0QFjAI&amp;url=http%3A%2F%2Fwww.iasted.org%2Fconferences%2Fformatting%2FPresentations-Tips.ppt&amp;ei=clfWTpjZEIblrAfC8qWXDg&amp;usg=AFQjCNEIgqx6x4ULHFXzzYDzCITuUJOczA&amp;sig2=0VtKXPvoDnIq-lIR4S9LEQ</a></p>

<p>while it would work for <a href="http://www.iasted.org/conferences/formatting/Presentations-Tips.ppt" rel="nofollow">http://www.iasted.org/conferences/formatting/Presentations-Tips.ppt</a></p>

<p>and both links are for the same file.</p>

<p><strong>How to solve the problem of redirection?</strong></p>
