Tutorial by Examples

Python 2.x2.7 Python 2 import urllib response = urllib.urlopen('http://stackoverflow.com/documentation/') Using urllib.urlopen() will return a response object, which can be handled similar to a file. print response.code # Prints: 200 The response.code represents the http return value. 20...
To POST data pass the encoded query arguments as data to urlopen() Python 2.x2.7 Python 2 import urllib query_parms = {'username':'stackoverflow', 'password':'me.me'} encoded_parms = urllib.urlencode(query_parms) response = urllib.urlopen("https://stackoverflow.com/users/login", enco...
The received bytes have to be decoded with the correct character encoding to be interpreted as text: Python 3.x3.0 import urllib.request response = urllib.request.urlopen("http://stackoverflow.com/") data = response.read() encoding = response.info().get_content_charset() html = d...

Page 1 of 1