urlparse
library is used in python
in order to well, parse a URL.Consider the example below:
from urlparse import urlparse
google_url = urlparse('https://www.google.com/profile?active=true#comment')
google_url
is now of type ParseResult
class, which includes all data we need:The protocol used in URL is achievable by:
print url.scheme
'https'
Absolute url of the google url is retrieved by
netloc
:print url.netloc
'www.google.com'
The path section of the URL which is after the domain section is:
print url.path
'/profile'
Query section of the URL:
print url.query
'active=true'
The
fragment
part of url is stored in fragment
attribute:print url.fragment
'comment'
#python #urlparse #url