Skip to content

Instantly share code, notes, and snippets.

@rugk
Last active June 11, 2016 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rugk/3ea35d04d66c2295e02d0b6cb6d822a2 to your computer and use it in GitHub Desktop.
Save rugk/3ea35d04d66c2295e02d0b6cb6d822a2 to your computer and use it in GitHub Desktop.
Python url download test
#!/usr/bin/env python
# LICENSE: CC0/Public Domain - To the extent possible under law, rugk has waived all copyright and related or neighboring rights to this work. This work is published from: Deutschland.
import sys
try:
from urllib.request import urlopen # Python 3
except ImportError:
from urllib2 import urlopen # Python 2
testurl = "https://..."
if len(sys.argv) >= 2:
testurl = sys.argv[1]
print "Accessing " + testurl + "..."
resp = urlopen(testurl)
respdata = resp.read()
print "RAW:"
print respdata
resp_data = respdata.decode('utf8').strip()
print "\nDecoded:"
print resp_data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment