Advertisement
furas

Python - work with URL

Feb 28th, 2017
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. text = '''https://www.facebook.com/ads/api/preview_iframe.php?d=AQKQ6mI94ehvRjxmfMP4MSwOOD&amp%3Bt=AQKSKiJH42m0Zxk5&hc_location=ufi'''
  4.  
  5. import html
  6. import urllib.parse
  7.  
  8. print('\n--- unquote ( convert %3B into ; ) ---\n')
  9.  
  10. url = urllib.parse.unquote(text)
  11. print(url)
  12.  
  13. print('\n--- unescape ( convert & into & ) ---\n')
  14.  
  15. url = html.unescape(url)
  16. print(url)
  17.  
  18. print('\n--- urlsplit ---\n')
  19.  
  20. url_parts = urllib.parse.urlsplit(url)
  21. print(url_parts)
  22.  
  23. print('\n--- parse_qs ---\n')
  24.  
  25. query = url_parts.query
  26. query_parts = urllib.parse.parse_qs(query)
  27. print(query_parts)
  28.  
  29. print('\n--------------------\n')
  30.  
  31. print('d:', query_parts['d'][0])
  32. print('t:', query_parts['t'][0])
  33. print('hc_location:', query_parts['hc_location'][0])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement