How to get the redirected URL only but not the actual content?

Peter Otten __peter__ at web.de
Fri Dec 1 11:08:47 EST 2017


Peng Yu wrote:

> Hi,
> 
> Does anybody know how only get the redirected URL but not the actual
> content?
> 
> I guess the request module probably should be used. But I am not sure
> how to do it exactly.
> 
> Can somebody show me the best way to request
> (https://doi.org/10.1109/5.771073) and get the URL
> (http://ieeexplore.ieee.org/document/771073/)? Thanks.
> 

How about

>>> from urllib.request import urlopen
>>> urlopen("https://doi.org/10.1109/5.771073").url
'http://ieeexplore.ieee.org:80/document/771073/?reload=true'

?




More information about the Python-list mailing list