1

In a loaded webpage address I want only base url and remove the tails. How can I get it please help me.

Imran
  • 31
  • 2
  • 7

1 Answers1

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