I am given the DOI address of an article, for example: 'https://doi.org/10.1093/qje/qjr041' How can I get the corresponding domain-specific URL or domain name ('https://academic.oup.com/') from that DOI using Python 3.0+?
Asked
Active
Viewed 381 times
1 Answers
1
You can do this using the requests module and allowing redirects.
For a crude example
import requests
from urllib.parse import urlparse
URL = "https://doi.org/10.1093/qje/qjr041" # Specify the DOI here
r = requests.get(URL,allow_redirects=True) # Redirects help follow to the actual domain
parsed_uri = urlparse(r.url) #url parse to get the scheme and domain name
result = '{uri.scheme}://{uri.netloc}/'.format(uri=parsed_uri)
print(result) # printing the result

Mustansir Godhrawala
- 53
- 1
- 6
-
You should probably change `get` to `head` because it is not necessary to download the content to resolve the doi. – Radio Controlled Mar 02 '23 at 11:18