python httplib2应用get post
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)
python httplib2应用get post的更多相关文章
- (Python基础教程之十三)Python中使用httplib2 – HTTP GET和POST示例
Python基础教程 在SublimeEditor中配置Python环境 Python代码中添加注释 Python中的变量的使用 Python中的数据类型 Python中的关键字 Python字符串操 ...
- 通过httplib2 探索的学习的最佳方式
在工作中需要对一个视频点播两百次,使其成为热门视频,才能对其p2p情况进行测试.虽然可以手动点播两百次,但是利用python发送200次post请求,能减少很多的工作量.该发送请求的方法用到了http ...
- HowToDoInJava 其它教程 2 · 翻译完毕
原文:HowToDoInJava 协议:CC BY-NC-SA 4.0 欢迎任何人参与和完善:一个人可以走的很快,但是一群人却可以走的更远. ApacheCN 学习资源 目录 JMS 教程 JMS 教 ...
- python中urllib, urllib2,urllib3, httplib,httplib2, request的区别
permike原文python中urllib, urllib2,urllib3, httplib,httplib2, request的区别 若只使用python3.X, 下面可以不看了, 记住有个ur ...
- Python安装httplib2 0.9.2
1.首先下载httplib2 0.9.2,下载地址: https://pypi.python.org/pypi/httplib2/#downloads 2.然后解压到Python27的安装目录下,将下 ...
- 洗礼灵魂,修炼python(60)--爬虫篇—httplib2模块
这里先要补充一下,Python3自带两个用于和HTTP web 服务交互的标准库(内置模块): http.client 是HTTP协议的底层库 urllib.request 建立在http.clien ...
- python中 urllib, urllib2, httplib, httplib2 几个库的区别
转载 摘要: 只用 python3, 只用 urllib 若只使用python3.X, 下面可以不看了, 记住有个urllib的库就行了 python2.X 有这些库名可用: urllib, urll ...
- Python 安装 httplib2
简述 httplib2 是一个使用 Python 写的支持的非常全面的 HTTP 特性的库.需要 Python2.3 或更高版本的运行环境,0.5.0 版及其以后包含了对 Python3 的支持. 简 ...
- python使用httplib2访问REST服务的例子
首先你需要安装httplib2,这个可以在github上找到: 然后你需要获得一个http连接的对象: con = httplib2.Http() 然后你需要发起连接: (6)resp, (5)c ...
随机推荐
- /src/struts.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC ...
- Codeforces Round #499 (Div. 2) C Fly题解
题目 http://codeforces.com/contest/1011/problem/C Natasha is going to fly on a rocket to Mars and retu ...
- Python 测试
(1)import doctest doctest.testmod(verbose=True) (2) pip install tests
- java工程师基础笔试题(一)
一.选择和填空 (不定项哦!) 1,如下是一份文件名为Test2.java的源文件,请问,编译该文件之后会生成几份字节码文件 class Test{ class Inner{} static cla ...
- Hibernate一对多关联映射的配置及其级联删除问题
首先举一个简单的一对多双向关联的配置: 一的一端:QuestionType类 package com.exam.entity; import java.util.Set; public class Q ...
- sql根据最小值去重
CREATE TABLE temp2 AS SELECT MAX(id) id FROM sys_oper_procenter GROUP BY pro_title 创建一个temp2的表 根据标题分 ...
- (django1.10)访问url报错Forbidden (CSRF cookie not set.): xxx
问题:页面访问时报错 Forbidden (CSRF cookie not set.): xxx 解决方法: 修改settings.py文件,注释掉 django.middleware.csr ...
- eclipse中没有tomcat小猫
安装了tomcat,按网上的说明也使用了tomcatPluginV331 配置文件,还是没有小猫,后来我发现,网上的tomcatPluginV331 针对eclipse 4.4版本,所以应该是插件的版 ...
- codeforces 722D Generating Sets 【优先队列】
You are given a set Y of n distinct positive integers y1, y2, ..., yn. Set X of n distinct positive ...
- FZU 2277 Change(dfs序+树状数组)
Problem Description There is a rooted tree with n nodes, number from 1-n. Root’s number is 1.Each no ...