#-*-coding:utf8 -*-
import urllib
import urllib2
url='http:reg.haibian.com/login/ajax_login'
#定义请求数据,并且对数据进行赋值
data={}
data['loginname']='student08@qq.com'
data['password']='96e79218965eb72c92a549dd5a330112'
#对请求数据进行编码
data=urllib.urlencode(data)
#将数据和url进行连接
request=url+'?'+data
requestResponse=urllib2.urlopen(request)
Responsestr=requestResponse.read()
print(requestResponse)
为什么我照老师的敲的,版本是2.7的,运行程序后报这个:
Traceback (most recent call last):
File "E:/Python文本程序/get.py", line 14, in <module>
requestResponse=urllib2.urlopen(request)
File "C:\Python27\lib\urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 427, in open
req = meth(req)
File "C:\Python27\lib\urllib2.py", line 1126, in do_request_
raise URLError('no host given')
URLError: <urlopen error no host given>
打印调用数据错了 应该是print(Responsestr)。。。。。