In a loaded webpage address I want only base url and remove the tails. How can I get it please help me.
Asked
Active
Viewed 2,993 times
1
-
You should add the [python] tag for better visibility. – cs95 Aug 12 '18 at 21:10
1 Answers
2
check out the urllib.parse
module:
you can use the urlparse
or urlsplit
methods to break up a url into components...
suppose you have the following url: http://example.com/foo?bar=1#baz
It is make up several components: a protocol scheme, network location, path, parameters, query string, and fragment.
for example:
from urllib.parse import urlparse
>>> url = 'http://example.com/foo?bar=1#baz'
>>> o = urlparse(url)
>>> o
ParseResult(scheme='http', netloc='example.com', path='/foo', params='', query='bar=1', fragment='baz')
>>> o.netloc
'example.com'

Corey Goldberg
- 59,062
- 28
- 129
- 143