给定文章的doi,如何使用Python获取域名?

发布于 2025-01-24 10:07:45 字数 100 浏览 2 评论 0原文

我得到了文章的DOI地址,例如:'https://doi.org/10.1093/qje/qjr041'如何获得相应的域特异性URL或域名(' .com/')使用Python 3.0+?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

似狗非友 2025-01-31 10:07:45

您可以使用请求模块并允许重定向执行此操作。

对于一个粗略的例子

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文