requests 在接收到302的时候会自动转移。可以通过history
>>> import requests
>>> r = requests.get('http://goo.gl/NZek5')
>>> r.history
(<Response [301]>,)
>>> r.history[0].status_code
301
>>> r.history[0].headers['Location']
'http://docs.python-requests.org/en/latest/user/quickstart/'
>>> r.url
u'http://docs.python-requests.org/en/latest/user/quickstart/'
>>> r = requests.get('http://goo.gl/NZek5', allow_redirects=False)
>>> r.status_code
301
>>> r.url
u'http://goo.gl/NZek5'
网友评论