从纯文本中解析URL

时间:2010-04-29 06:27:53

标签: python url parsing

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

我们将非常感谢Python中的任何代码示例。

2 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分:1)

请参阅Jan Goyvaerts' blog

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

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