Convert string to URL
Tags: #python #urllib #string #url #convert #library
Last update: 2023-04-12 (Created: 2023-03-29)
Description: This notebook will show how to convert a string to a URL using urllib.
References:
import urllib.parse
string
: string to be converted to URL
string = "This is a string"
The
quote()
function replaces special characters in the string with their percent-encoded equivalent, which is necessary for URLs. The resulting URL can be used in your Python code or in a web browser.
Note that if you need to convert the URL back to a string, you can use the unquote()url = urllib.parse.quote(string)
print(url)
Last modified 1mo ago