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 ...
随机推荐
- 如何高效的使用Google
文章再转自知乎:http://www.zhihu.com/question/20161362
- [剑指Offer] 51.构建乘积数组
题目描述 给定一个数组A[0,1,...,n-1],请构建一个数组B[0,1,...,n-1],其中B中的元素B[i]=A[0]*A[1]*...*A[i-1]*A[i+1]*...*A[n-1].不 ...
- AC自动机裸题
HDU 2222 Keywords Search 模板题.对模式串建立AC自动机然后在trie树上找一遍目标串即可. # include <cstdio> # include <cs ...
- C# 大文件的复制方法
如何复制读取大文件,也许困惑了很多人很长时间,这个不知道怎么搞,的确让人头疼欲裂,知道了你就才发现原来那么简单,话不多说,直入正题```` static void Main(string[] args ...
- I/O复用----poll
2018-08-01 (星期三)poll(): #include <sys/poll.h> int poll (struct pollfd *fd, unsigned int nfds, ...
- BZOJ4200 & 洛谷2304 & UOJ132:[NOI2015]小园丁与老司机——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=4200 https://www.luogu.org/problemnew/show/P2304 ht ...
- 洛谷 P1363 幻想迷宫 解题报告
P1363 幻想迷宫 题目描述 背景 Background (喵星人LHX和WD同心协力击退了汪星人的入侵,不幸的是,汪星人撤退之前给它们制造了一片幻象迷宫.) WD:呜呜,肿么办啊-- LHX:mo ...
- X day4
题目 官方题解 T1: 单调栈,单调队列因为认为考场上会写崩所以写了一个十分暴力的方法(线段树) 然后做一做区间覆盖即可 #include<iostream> #include<cs ...
- 【二分】【P1314】 【NOIP2011D2T2】聪明的质监员
传送门 Description 小T 是一名质量监督员,最近负责检验一批矿产的质量.这批矿产共有 \(n\) 个矿石,从 \(1\) 到 \(n\) 逐一编号,每个矿石都有自己的重量 \(w_i\) ...
- HDU 1715 大数java
大菲波数 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...