标签:
import httplib2,time#装饰器方法,用于记录方法消耗时间#推荐将print 改成logdef timer(func):def _warpper(self,*argv):start = time.time()result = func(self,*argv)cost = time.time() - startprint ‘The function %s coust time %f sec‘ % (func.func_name,cost)return resultreturn _warpperclass Spider(object):"""docstring for Spider"""def __init__(self):super(Spider, self).__init__()self.h = httplib2.Http(‘.cache‘)@timerdef httpGet(self,urlstr,word=""):#httplib2.debuglevel = 1urlstr = urlstrself.head,self.content = self.h.request(urlstr)#print(content)@timerdef httpPost(self,urlstr,data):from urllib import urlencodeself.head,self.content = self.h.request(urlstr, ‘POST‘, urlencode(data), headers={‘Content-Type‘: ‘application/x-www-form-urlencoded‘})def getContent(self):return self.content.decode(‘utf-8‘)def getResponse(self):return self.head- #post传参数据
data = {‘password‘:‘s2105535‘,‘submit‘:‘Login‘,‘username‘:‘qq64397232‘}spider = Spider()spider.httpPost(‘http:/12121212.com‘,data)
标签:
原文地址:http://www.cnblogs.com/snifferhu/p/4622789.html