1

我有一个网址:

https://www.facebook.com/dialog/oauth?client_id=559149457475028&redirect_uri=https://calm-refuge-2106.herokuapp.com/&scope=publish_stream

它使用 url 重定向到另一个页面:

https://calm-refuge-2106.herokuapp.com/?code=AQAoBPyS4lKynHM4lylFHChFyO775T-49A1j8DbTGO9iiyoKnkDv0naSWMSvJ26ISt50fTUGcYH8QfUdLwt4sLBQ9noNmBCuUsze4rVSjxCcJ1pbfcLpfy2OyLB5DMg7sOWr_q5dEHNEd9eXoeRepmjFDU7GyEUx6WrjDtIOcusH4prnPGhQ2gHopJC54AeflMC9bh6fP2R6OhAJhVCVMHNvIT2wwTB8DG46yoRP1GAqN-d2vm8RwOC93vY-Xv_HvGQKwhRxbpVlk2vWTMQ40F1rbaw_zJNz7oBtz7qDUQkxI3RcE6dWw5GEzPcFMFuD1jw#_=_

我只需要进行代码查询。

当我使用urllib.urlopen打开 url,然后使用geturl方法返回类似文件的对象时,它返回如下内容:https://www.facebook.com/login.php?skip_api_login=1&api_key=559149457475028&signed_next=1&next=https%3A%2F%2Fwww.facebook.com%2Fdialog%2Foauth%3Fredirect_uri%3Dhttps%253A%252F%252Fcalm-refuge-2106.herokuapp.com%252F%26scope%3Dpublish_stream%26client_id%3D559149457475028%26ret%3Dlogin&cancel_uri=https%3A%2F%2Fcalm-refuge-2106.herokuapp.com%2F%3Ferror%3Daccess_denied%26error_code%3D200%26error_description%3DPermissions%2Berror%26error_reason%3Duser_denied%23_%3D_&display=page

这显然不是我想要的。

在 Python 中重定向后如何获取 url?

4

1 回答 1

1

尝试urllib2.HTTPRedirectHandler

于 2013-08-26T00:49:01.527 回答