Links

Convert URL to string

Tags: #python #urllib #string #url #convert #library
Author: Florent Ravenel
Last update: 2023-04-12 (Created: 2023-03-29)
Description: This notebook will show how to convert a URL to a string using urllib.
References:

Input

Import libraries

import urllib.parse

Setup Variables

  • url: URL to be converted to string
url = "https://www.pythonforbeginners.com/urllib/how-to-use-urllib-in-python"

Model

Convert URL to string

The unquote() function in urllib.parse converts percent-encoded characters in the URL back to their original form. In this example, the URL is already in string form, so unquote() simply returns the same string. If the URL had any percent-encoded characters, they would be decoded by unquote().
string = urllib.parse.unquote(url)

Output

Display result

print(string)