从python中的字符串中提取所有URL

时间:2014-09-22 00:35:44

标签: python string

给定一串文本,其中可能包含多个以http://

开头的网址

例如:

someString = "Text amongst words and links http://www.text.com more text more text another http http://www.word.com"

如何从字符串中提取所有网址?

离开

http://www.text.com

http://www.word.com

2 个答案:

答案 0 :(得分:1)

你想要正则表达式。

在python中:https://docs.python.org/2/library/re.html

要评估的正则表达式:http://daringfireball.net/2010/07/improved_regex_for_matching_urls

不应该从那里带你很长时间

答案 1 :(得分:1)

这应该有效:

>>> for url in re.findall('(http://\S+)', someString): print url
... 
http://www.text.com
http://www.word.com
相关问题