1. import httplib2,time
  2. #装饰器方法,用于记录方法消耗时间
  3. #推荐将print 改成log
  4. def timer(func):
  5.     def _warpper(self,*argv):
  6.         start       = time.time()
  7.         result      = func(self,*argv)
  8.         cost        = time.time() - start
  9.         print 'The function %s coust time %f sec' % (func.func_name,cost)
  10.         return result
  11.     return _warpper
  12. class Spider(object):
  13.     """docstring for Spider"""
  14.     def __init__(self):
  15.         super(Spider, self).__init__()
  16.         self.h = httplib2.Http('.cache') 
  17.     
  18.     @timer
  19.     def httpGet(self,urlstr,word=""):
  20.         #httplib2.debuglevel = 1
  21.         urlstr = urlstr
  22.         self.head,self.content = self.h.request(urlstr)
  23.         #print(content)
  24.     
  25.     @timer
  26.     def httpPost(self,urlstr,data):
  27.         from urllib import urlencode
  28.       
  29.         self.head,self.content = self.h.request(urlstr, 'POST', urlencode(data), headers={'Content-Type': 'application/x-www-form-urlencoded'})
  30.     def getContent(self):
  31.         return self.content.decode('utf-8')
  32.     def getResponse(self):
  33.         return self.head
  34. #post传参数据
  35. data    = {'password':'s2105535','submit':'Login','username':'qq64397232'}
  36. spider = Spider()
  37. spider.httpPost('http:/12121212.com',data)

python httplib2应用get post的更多相关文章

  1. (Python基础教程之十三)Python中使用httplib2 – HTTP GET和POST示例

    Python基础教程 在SublimeEditor中配置Python环境 Python代码中添加注释 Python中的变量的使用 Python中的数据类型 Python中的关键字 Python字符串操 ...

  2. 通过httplib2 探索的学习的最佳方式

    在工作中需要对一个视频点播两百次,使其成为热门视频,才能对其p2p情况进行测试.虽然可以手动点播两百次,但是利用python发送200次post请求,能减少很多的工作量.该发送请求的方法用到了http ...

  3. HowToDoInJava 其它教程 2 · 翻译完毕

    原文:HowToDoInJava 协议:CC BY-NC-SA 4.0 欢迎任何人参与和完善:一个人可以走的很快,但是一群人却可以走的更远. ApacheCN 学习资源 目录 JMS 教程 JMS 教 ...

  4. python中urllib, urllib2,urllib3, httplib,httplib2, request的区别

    permike原文python中urllib, urllib2,urllib3, httplib,httplib2, request的区别 若只使用python3.X, 下面可以不看了, 记住有个ur ...

  5. Python安装httplib2 0.9.2

    1.首先下载httplib2 0.9.2,下载地址: https://pypi.python.org/pypi/httplib2/#downloads 2.然后解压到Python27的安装目录下,将下 ...

  6. 洗礼灵魂,修炼python(60)--爬虫篇—httplib2模块

    这里先要补充一下,Python3自带两个用于和HTTP web 服务交互的标准库(内置模块): http.client 是HTTP协议的底层库 urllib.request 建立在http.clien ...

  7. python中 urllib, urllib2, httplib, httplib2 几个库的区别

    转载 摘要: 只用 python3, 只用 urllib 若只使用python3.X, 下面可以不看了, 记住有个urllib的库就行了 python2.X 有这些库名可用: urllib, urll ...

  8. Python 安装 httplib2

    简述 httplib2 是一个使用 Python 写的支持的非常全面的 HTTP 特性的库.需要 Python2.3 或更高版本的运行环境,0.5.0 版及其以后包含了对 Python3 的支持. 简 ...

  9. python使用httplib2访问REST服务的例子

    首先你需要安装httplib2,这个可以在github上找到: 然后你需要获得一个http连接的对象: con = httplib2.Http()   然后你需要发起连接: (6)resp, (5)c ...

随机推荐

  1. Using Service Workers

    [Using Service Workers] 1.This is an experimental technology Because this technology's specification ...

  2. 检查WMI协议是否通的

    在APM上的运行执行“wbemtest”,然后在上面的root\sivm前面加RPC不通的机器,先查WMI协议是否是通的

  3. vmware 完全关闭时间同步

    参考 http://blog.51cto.com/hezhang/1535577 修改.vmx文件 tools.syncTime = "FALSE" time.synchroniz ...

  4. 设置input标签的placeholder的样式

    设置input样式代码: input::-webkit-input-placeholder{ /*WebKit browsers*/ color: red; } input::-moz-input-p ...

  5. centos 7 下 Ceph 配置安装

    一.环境介绍 系统: CentOS Linux release 7.3.1611 (Core) 硬盘: 系统盘:300GB*2-raid 1 OSD:600GB*4-raid 5      ceph ...

  6. linux之master和minion

    saltstack博客地址: https://www.cnblogs.com/pyyu/p/9465608.html在线yaml文件编写:http://www.bejson.com/validator ...

  7. 使用phpStudyy运行tipask

    tipask官网:https://www.tipask.com/tipask源码下载:https://www.tipask.com/download.html 可参考此处安装文档的链接 除此之外可以参 ...

  8. 填坑专记-手脱FSG壳

      妈呀,脱FGS壳真的是坎坷颇多,多亏吾爱破解前辈们的帮忙.我一定要记录下来,省的以后再无法解决.   已经查看是FSG壳了.找到入口也容易了.重点就是脱壳并修复好它. 脱壳   OEP为:   使 ...

  9. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  10. Git之清除已保存的账户

    Git会自动保存输入过的用户名.密码. Git的配置文件是-/.gitconfig.可在windows下的GIt Bash.Mac的命令行中,用vim ~/.gitconfig打开. Windows ...