标签:
post方式
# -*- coding:utf-8 -*-
import urllib.parse #python2 在这道程序中只需引入urllib
import urllib.request #python 在这道程序中引入urllib2
values = {}
values[‘username‘]="借物少年"
values[‘password‘]="XXXXXXX"
data=urllib.parse.urlencode(values).encode(encoding=‘utf-8‘)
url="http://passport.cnblogs.com/user/signin?ReturnUrl=http%3A%2F%2Fwww.cnblogs.com%2F"
request1=urllib.request.Request(url,data)
response1=urllib.request.urlopen(request1)
print (response1.read())
Get方式
# -*- coding:utf-8 -*-
import urllib.parse #python2 在这道程序中只需引入urllib
import urllib.request #python 在这道程序中引入urllib2
values = {}
values[‘username‘]="借物少年"
values[‘password‘]="XXXXXXX"
data=urllib.parse.urlencode(values).encode(encoding=‘utf-8‘)
url="http://passport.cnblogs.com/user/signin?ReturnUrl=http%3A%2F%2Fwww.cnblogs.com%2F"
geturl1=url+"?"+str(data)
request1=urllib.request.Request(geturl1)
response1=urllib.request.urlopen(request1)
print (response1.read())
标签:
原文地址:http://www.cnblogs.com/pkmnexp/p/4703484.html