Last active
March 12, 2019 21:24
-
-
Save hamletbatista/bf0d3b01369fab342c1d1e6fb6dbc4eb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#decode URL-econded URL | |
url_source="/url?sa=t&source=web&rct=j&url=https://support.google.com/webmasters/answer/35291%3Fhl%3Den&ved=2ahUKEwi42-aIwP3gAhUNON8KHf4EB-QQFjAIegQIChAB" | |
u = urlsplit(url_source) | |
print(u.query) | |
#Output -> 'sa=t&source=web&rct=j&url=https://support.google.com/webmasters/answer/35291%3Fhl%3Den&ved=2ahUKEwi42-aIwP3gAhUNON8KHf4EB-QQFjAIegQIChAB' | |
#note the parameter 'url' is URL encoded because it includes a query string | |
url_params = parse_qs(u.query) | |
print(url_params["url"]) | |
#Output -> ['https://support.google.com/webmasters/answer/35291?hl=en'] | |
#in case the URL is already encoded | |
encoded_url='https://support.google.com/webmasters/answer/35291%3Fhl%3Den' | |
print(unquote(encoded_url)) | |
#Output -> 'https://support.google.com/webmasters/answer/35291?hl=en' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment