urllib

https://docs.python.org/3/library/urllib.html

Table of Contents

Check if a URL is absolute howto

from urllib.parse import urlparse

def is_absolute(url):
    return bool(urlparse(url).netloc)

print(is_absolute('https://yeonghoey.com/python'))
print(is_absolute('python/_img'))
True
False

Remove the fragment from a URL howto

from urllib.parse import urldefrag
tuple_ = urldefrag('https://yeonghoey.com/python/#how-to')
print(tuple_)
DefragResult(url='https://yeonghoey.com/python/', fragment='how-to')