DeaD_EyE

decode amazon links

Apr 13th, 2022
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | None | 0 0
  1. from base64 import b64decode
  2. from urllib.parse import urlparse, unquote
  3.  
  4.  
  5. def parse_query(query):
  6.     return dict(item.split("=", maxsplit=1) for item in unquote(query).split("&"))
  7.  
  8.  
  9. def query(url):
  10.     query = urlparse(url).query
  11.     result = parse_query(query)
  12.     # if spLa exists, it's a base64 encoded string
  13.     # decoding it and creating a sub-dict of it
  14.     if "spLa" in result:
  15.         result["spLa"] = parse_query(b64decode(result["spLa"]))
  16.  
  17.     return result
Add Comment
Please, Sign In to add comment