Skip to content

Instantly share code, notes, and snippets.

@zed
Created February 25, 2012 17:34
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 zed/fa9e9efc83a53df02e29 to your computer and use it in GitHub Desktop.
Save zed/fa9e9efc83a53df02e29 to your computer and use it in GitHub Desktop.
print page info
try:
from urllib2 import urlopen
except ImportError:
from urllib.request import urlopen
url, encoding = 'http://stackoverflow.com/q/9445627/', 'utf-8'
response = urlopen(url)
print(response.info())
page_bytes = response.read()
print("Raw bytes:")
print(repr(page_bytes[:40]))
print("Decoded:")
print(page_bytes.decode(encoding))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment