Given a DOI of an article, how can I get the domain name using python?

527 views Asked by At

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+?

1

There are 1 answers

1
Mustansir Godhrawala On BEST ANSWER

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