【问题标题】:Parse URL from plain text从纯文本解析 URL
【发布时间】:2023-04-05 13:27:01
【问题描述】:

如何从任何给定的纯文本(不限于标签中的 href 属性)解析 URL?

任何 Python 中的代码示例都将受到赞赏。

【问题讨论】:

标签: python url parsing


【解决方案1】:

Jan Goyvaerts' blog

所以一个 Python 代码示例可能看起来像

result = re.findall(r"\b(?:(?:https?|ftp|file)://|www\.|ftp\.)[-A-Z0-9+&@#/%=~_|$?!:,.]*[A-Z0-9+&@#/%=~_|$]", subject)

【讨论】:

    【解决方案2】:

    您可以使用Regular Expression 来解析字符串。

    查看之前提出的这个问题: What’s the cleanest way to extract URLs from a string using Python?

    【讨论】:

      猜你喜欢
      • 2011-04-08
      • 1970-01-01
      • 2013-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多