【问题标题】:How to extract the DOI sub-string from a URL string? [python] [closed]如何从 URL 字符串中提取 DOI 子字符串? [蟒蛇] [关闭]
【发布时间】:2021-01-22 18:37:32
【问题描述】:

我有以下格式的网址列表:

https://doi.org/10.1145/2883851.2883900

我想提取“doi.org”之后的值。在示例中,我的预期输出是:

10.1145/2883851

我可以在单个 url 上执行此操作,但要应用如何从 URL 列表中获取值。

【问题讨论】:

  • 如果是同一个网站:extracted = [string.replace("https://doi.org/", "") for string in lst]
  • 对于字符串 i in lst 我想你想要的,还是我会?
  • 是的,对不起,我怎么把 in 放了两次
  • 如果您可以对单个 URL 执行此操作,则对列表中的所有 URL 执行此操作只需遍历列表即可。看起来您可能会发现 python 教程很有帮助。网上有很多不错的。这是一个很好的:learnpython.org/en/Loops

标签: python python-3.x


【解决方案1】:

如果你有一个同域名的url列表,想要返回10.1145/2883851格式的值列表:

def replace_url(urls):
    result = []
    for url in urls:
        result.append(url[16:]) # len of "https://doi.org/" is 16
    return result 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-14
    • 2017-01-11
    • 2011-11-17
    • 1970-01-01
    • 2012-11-05
    • 1970-01-01
    相关资源
    最近更新 更多