I\'ve been trying to figure out what the best way to validate a URL is (specifically in Python) but haven\'t really been able to find an answer. It seems like there isn\'t o
This looks like it might be a duplicate of How do you validate a URL with a regular expression in Python?
You should be able to use the urlparse
library described there.
>>> from urllib.parse import urlparse # python2: from urlparse import urlparse
>>> urlparse('actually not a url')
ParseResult(scheme='', netloc='', path='actually not a url', params='', query='', fragment='')
>>> urlparse('http://google.com')
ParseResult(scheme='http', netloc='google.com', path='', params='', query='', fragment='')
call urlparse
on the string you want to check and then make sure that the ParseResult
has attributes for scheme
and netloc