pythonurlparsing

Extracting a URL in Python


In regards to: Find Hyperlinks in Text using Python (twitter related)

How can I extract just the url so I can put it into a list/array?


Edit

Let me clarify, I don't want to parse the URL into pieces. I want to extract the URL from the text of the string to put it into an array. Thanks!


Solution

  • In response to the OP's edit I hijacked Find Hyperlinks in Text using Python (twitter related) and came up with this:

    import re
    
    myString = "This is my tweet check it out http://example.com/blah"
    
    print(re.search("(?P<url>https?://[^\s]+)", myString).group("url"))