Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading