1、import urllib2
response = urllib2.urlopen("http://www.baidu.com")
print response.read()
2、POST方式:
import urllib
import urllib2
values = {"username":"1016903103@qq.com","password":"XXXX"}
data = urllib.urlencode(values)
url = "https://passport.csdn.net/account/login?from=http://my.csdn.net/my/mycsdn"
request = urllib2.Request(url,data)
response = urllib2.urlopen(request)
print response.read()
3、GET方式:
直接把参数写到网址上面,直接构建一个带参数的URL出来即可
geturl = url + "?"+data
request = urllib2.Request(geturl)
response = urllib2.urlopen(request)
print response.read()
print geturl,打印输出一下url,发现其实就是原来的url加?然后加编码后的参数