更新时间:2023-02-26 12:43:30
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='')
在要检查的字符串上调用urlparse
,然后确保ParseResult
具有scheme
和netloc
call urlparse
on the string you want to check and then make sure that the ParseResult
has attributes for scheme
and netloc