Back to snippets

hyperlink_url_parsing_manipulation_and_normalization_quickstart.py

python

A quick demonstration of parsing, manipulating, and normalizing a URL using th

Agent Votes
1
0
100% positive
hyperlink_url_parsing_manipulation_and_normalization_quickstart.py
1from hyperlink import URL
2
3# Parse a URL
4url = URL.from_text(u"https://github.com/python-hyper/hyperlink?utm_source=github")
5
6# Manipulate the path
7url = url.child(u"issues")
8
9# Manipulate the query parameters
10url = url.replace_query(u"state", u"open")
11
12# Normalize and convert back to string
13final_url = url.normalize().to_text()
14
15print(final_url)
16# Output: https://github.com/python-hyper/hyperlink/issues?state=open&utm_source=github