python模块(requests,logging)
一、requests
Requests 是使用 Apache2 Licensed 许可证的 基于Python开发的HTTP 库,其在Python内置模块的基础上进行了高度的封装,从而使得Pythoner进行网络请求时,变得美好了许多,使用Requests可以轻而易举的完成浏览器可有的任何操作。
1、安装模块
pip3 install requests
2、使用模块
(1)无参数实例
>>> import requests
>>> ret = requests.get('https://www.baidu.com')
>>> ret.url
'https://www.baidu.com/'
>>> ret.text
'<!DOCTYPE html>\r\n<!--STATUS OK--><html> <head><meta http-equiv=content-type c
ontent=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge>
<meta content=always name=referrer><link rel=stylesheet type=text/css href=https...
(2)有参数实例
>>> ret = requests.get("http://httpbin.org/get", params=payload)
>>> ret.url
'http://httpbin.org/get?key1=value1&key2=value2'
>>> ret.text
'{\n "args": {\n "key1": "value1", \n "key2": "value2"\n }, \n "headers
": {\n "Accept": "*/*", \n "Accept-Encoding": "gzip, deflate", \n "Host
": "httpbin.org", \n "User-Agent": "python-requests/2.12.1"\n }, \n "origin
": "101.254.232.211", \n "url": "http://httpbin.org/get?key1=value1&key2=value2
Get请求
1、基本post实例
>>> payload = {'key1': 'value1', 'key2': 'value2'}
>>> ret = requests.post("http://httpbin.org/post", data=payload)
>>> ret.text
'{\n "args": {}, \n "data": "", \n "files": {}, \n "form": {\n "key1": "v
alue1", \n "key2": "value2"\n }, \n "headers": {\n "Accept": "*/*", \n
"Accept-Encoding": "gzip, deflate", \n "Content-Length": "", \n "Conte
nt-Type": "application/x-www-form-urlencoded", \n "Host": "httpbin.org", \n
"User-Agent": "python-requests/2.12.1"\n }, \n "json": null, \n "origin": "
101.254.232.211", \n "url": "http://httpbin.org/post"\n}\n' 2、发送请求头和数据实例 >>> import requests
>>> import json
>>>
... url = 'https://api.github.com/some/endpoint'
>>> payload = {'some': 'data'}
>>> headers = {'content-type': 'application/json'}
>>>
... ret = requests.post(url, data=json.dumps(payload), headers=headers)
>>> ret.text
'{"message":"Not Found","documentation_url":"https://developer.github.com/v3"}'
>>> ret.cookies
<RequestsCookieJar[]>
post请求
requests.get(url, params=None, **kwargs)
requests.post(url, data=None, json=None, **kwargs)
requests.put(url, data=None, **kwargs)
requests.head(url, **kwargs)
requests.delete(url, **kwargs)
requests.patch(url, data=None, **kwargs)
requests.options(url, **kwargs) # 以上方法均是在此方法的基础上构建
requests.request(method, url, **kwargs)
其他请求
参考:http://www.cnblogs.com/wupeiqi/articles/5501365.html
http://cn.python-requests.org/zh_CN/latest/
二、logging
http://www.cnblogs.com/wupeiqi/articles/5501365.html
第十点logging日志模块
python模块(requests,logging)的更多相关文章
- python 模块之-logging
python 模块logging import logging ### 简单使用格式 日志级别等级CRITICAL > ERROR > WARNING > INFO > ...
- python初步学习-python模块之 logging
logging 许多应用程序中都会有日志模块,用于记录系统在运行过程中的一些关键信息,以便于对系统的运行状况进行跟踪.在python中,我们不需要第三方的日志组件,python为我们提供了简单易用.且 ...
- Python模块学习 ---- logging 日志记录
许多应用程序中都会有日志模块,用于记录系统在运行过程中的一些关键信息,以便于对系统的运行状况进行跟踪.在.NET平台中,有非常著名的第三方开源日志组件log4net,c++中,有人们熟悉的log4cp ...
- Python 模块之Logging——常用handlers的使用
一.StreamHandler 流handler——包含在logging模块中的三个handler之一. 能够将日志信息输出到sys.stdout, sys.stderr 或者类文件对象(更确切点,就 ...
- Python模块-requests模块使用
写在前面 这篇文章是我照着廖雪峰python网站学习的,大致内容差不多,多了我一丢丢的自己的想法.如果发现有什么不对的话请及时联系我.qq:472668561 参考链接:https://www.lia ...
- python模块之logging
在现实生活中,记录日志非常重要.银行转账时会有转账记录:飞机飞行过程中,会有黑盒子(飞行数据记录器)记录飞行过程中的一切.如果有出现什么问题,人们可以通过日志数据来搞清楚到底发生了什么.对于系统开发. ...
- Python模块之 - logging
日志是非常重要的,最近有接触到这个,所以系统的看一下Python这个模块的用法.本文即为Logging模块的用法简介,主要参考文章为Python官方文档,链接见参考列表. Logging模块构成 组成 ...
- 【python模块】——logging
python学习——logging模块
- Python模块:logging、
logging模块: 很多程序都有记录日志的需求,并且日志中包含的信息既有正常的程序访问日志,还可能有错误.警告等信息输出.Python的logging模块提供了标准的日志接口,你可以通过它存储各种格 ...
- python模块学习 logging
1.简单的将日志打印到屏幕 import logging logging.debug('This is debug message') logging.info('This is info messa ...
随机推荐
- 【bzoj1705】[Usaco2007 Nov]Telephone Wire 架设电话线 dp
题目描述 最近,Farmer John的奶牛们越来越不满于牛棚里一塌糊涂的电话服务 于是,她们要求FJ把那些老旧的电话线换成性能更好的新电话线. 新的电话线架设在已有的N(2 <= N < ...
- OpenCV2.3.1在Win7+VS2010下的配置过程
1. 假定电脑上已经安装了VS2010程序,若没有,首先安装vs2010.下载OpenCV2.3.1,网址:http://sourceforge.net/projects/opencvlibrary ...
- 【以前的空间】bzoj 1227 [SDOI2009]虔诚的墓主人
题解:hzw大神的博客说的很清楚嘛 http://hzwer.com/1941.html 朴素的做法就是每个点如果它不是墓地那么就可形成十字架的数量就是这个c(点左边的树的数量,k)*c(点右边的树的 ...
- BZOJ2844:albus就是要第一个出场——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=2844 已知一个长度为n的正整数序列A(下标从1开始), 令 S = { x | 1 <= x ...
- solr单元测试
package com.taotao.rest.solr; import java.io.IOException; import org.apache.solr.client.solrj.SolrQu ...
- iOS更改项目名称的详细步骤
http://www.cocoachina.com/ios/20150104/10824.html
- ACM2112迪克斯特算法
HDU Today Problem Description 经过锦囊相助,海东集团终于度过了危机,从此,HDU的发展就一直顺风顺水,到了2050年,集团已经相当规模了,据说进入了钱江肉丝经济开发区50 ...
- Moodle插件开发系列——XMLDB编辑器
Moodle插件开发系列——XMLDB编辑器 位置:网站管理>开发> XML编辑器 l XML编辑器是制作install.xml文件的工具,而install.xml是指定Moodle建立 ...
- jquery获取textarea内容为空的问题
使用 定义了一个textarea,在使用jquery的方法获取文本内容的时候总是为空. var content = $("#content").val(); 后来测试发现,id不能 ...
- LightOJ 1278 - Sum of Consecutive Integers 分解奇因子 + 思维
http://www.lightoj.com/volume_showproblem.php?problem=1278 题意:问一个数n能表示成几种连续整数相加的形式 如6=1+2+3,1种. 思路:先 ...