可能有几种方法可以做到这一点,但最干净的方法是使用正则表达式
>>> myString = "This is a link http://www.google.com">>> print re.search("(?P<url>https?://[^s]+)", myString).group("url")http://www.google.com如果可以有多个链接,则可以使用类似于以下内容的链接
>>> myString = "These are the links http://www.google.com and http://stackoverflow.com/questions/839994/extracting-a-url-in-python">>> print re.findall(r'(https?://[^s]+)', myString)['http://www.google.com', 'http://stackoverflow.com/questions/839994/extracting-a-url-in-python']>>>



