views:

35

answers:

2

i try to fetch data from web,but the page use a 302 redirect how can i use python to fetch the real url?

+2  A: 

Have a look at chapter 11.7. Handling redirects from the Dive Into Python series. It explains your entire issue in quite a bit of detail, example code and all.

Stigma
A: 

What are you currently using? Both urllib and urllib2 should handle it automatically:

page = urllib.urlopen('http://mrozekma.com/302test.php')
>>> print page.geturl()   # This will show the redirected-to URL
http://mrozekma.com/302test.php?success
>>> print page.readlines()
['Success']
Michael Mrozek