On Jun 14, 5:22 pm, Fernando Rodriguez
<[EMAIL PROTECTED]> wrote:
> Hi,
>
> I'musing urllib to download pages from a site. How can I detect if a given
> url is being redirected somewhere else? I want to avoid this, is it possible?
>
> Thanks in advance!

Try this:

import urllib
url_opener = urllib.URLopener() # create URLopener
#You could also work with urllib.FancyURLopener

try:
    data = url_opener.open("http://www.somedomain.com/index.html";)   #
open index.html
except IOError, error_code:
    if error_code[0] == "http error":
        if error_code[1] == 301:
            #do something here
        if error_code[2] == 302:
            #do something here

I hope that's of some help!  I think you may want to delve deeper into
FancyURLopener...
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to