一、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)的更多相关文章

  1. python 模块之-logging

    python  模块logging import logging ###  简单使用格式    日志级别等级CRITICAL > ERROR > WARNING > INFO > ...

  2. python初步学习-python模块之 logging

    logging 许多应用程序中都会有日志模块,用于记录系统在运行过程中的一些关键信息,以便于对系统的运行状况进行跟踪.在python中,我们不需要第三方的日志组件,python为我们提供了简单易用.且 ...

  3. Python模块学习 ---- logging 日志记录

    许多应用程序中都会有日志模块,用于记录系统在运行过程中的一些关键信息,以便于对系统的运行状况进行跟踪.在.NET平台中,有非常著名的第三方开源日志组件log4net,c++中,有人们熟悉的log4cp ...

  4. Python 模块之Logging——常用handlers的使用

    一.StreamHandler 流handler——包含在logging模块中的三个handler之一. 能够将日志信息输出到sys.stdout, sys.stderr 或者类文件对象(更确切点,就 ...

  5. Python模块-requests模块使用

    写在前面 这篇文章是我照着廖雪峰python网站学习的,大致内容差不多,多了我一丢丢的自己的想法.如果发现有什么不对的话请及时联系我.qq:472668561 参考链接:https://www.lia ...

  6. python模块之logging

    在现实生活中,记录日志非常重要.银行转账时会有转账记录:飞机飞行过程中,会有黑盒子(飞行数据记录器)记录飞行过程中的一切.如果有出现什么问题,人们可以通过日志数据来搞清楚到底发生了什么.对于系统开发. ...

  7. Python模块之 - logging

    日志是非常重要的,最近有接触到这个,所以系统的看一下Python这个模块的用法.本文即为Logging模块的用法简介,主要参考文章为Python官方文档,链接见参考列表. Logging模块构成 组成 ...

  8. 【python模块】——logging

    python学习——logging模块

  9. Python模块:logging、

    logging模块: 很多程序都有记录日志的需求,并且日志中包含的信息既有正常的程序访问日志,还可能有错误.警告等信息输出.Python的logging模块提供了标准的日志接口,你可以通过它存储各种格 ...

  10. python模块学习 logging

    1.简单的将日志打印到屏幕 import logging logging.debug('This is debug message') logging.info('This is info messa ...

随机推荐

  1. 创建 cordova 项目

    1. 安装 node.js 2.安装 cordova : npm install -g cordova 3.创建 安卓项目: cordova create <项目路径>  <包名&g ...

  2. 【转载】input只改变光标的颜色 不改变字的颜色

    转载 http://www.cnblogs.com/yangAL/p/6934608.html color: red; text-shadow: 0px 0px 0px #000; -webkit-t ...

  3. c#对xml的操作

    操作xml可以通过XElement对象,比较方便的使用列举以下几点: 把字符串转变成XElement,保存成xml文件,加载xml文件: //把字符串解析成XElement对象 string str ...

  4. RT-thread main函数分析

    RT-thread系统的main函数位于startup.c文件中. /** * This function will startup RT-Thread RTOS. */ void rtthread_ ...

  5. 在a标签的href用户#name 的可以实现页面 上下跳转

  6. bzoj2437-兔兔与蛋蛋

    题目 分析 第一次做这种题,其实很简单. 只能经过一次的博弈可以考虑转化为二分图博弈. 棋盘上有黑白色的棋子,可以把这个游戏看作空格在棋子间移动,于是就想到,把棋盘黑白染色,以空格为黑,那么空格的移动 ...

  7. JavaScript 面向对象开发知识基础总结

    JavaScript 面向对象开发知识基础总结 最近看了两本书,书中有些内容对自己还是很新的,有些内容是之前自己理解不够深的,所以拿出来总结一下,这两本书的名字如下: JavaScript 面向对象精 ...

  8. Python type()函数用途及使用方法

    函数可以做什么 在介绍数据类型的文章中提到过,要怎么样查看对像的数据类型.type()就是一个最实用又简单的查看数据类型的方法.type()是一个内建的函数,调用它就能够得到一个反回值,从而知道想要查 ...

  9. 【BZOJ5301】【CQOI2018】异或序列(莫队)

    [BZOJ5301][CQOI2018]异或序列(莫队) 题面 BZOJ 洛谷 Description 已知一个长度为 n 的整数数列 a[1],a[2],-,a[n] ,给定查询参数 l.r ,问在 ...

  10. BZOJ2049:[SDOI2008]洞穴勘测——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=2049 https://www.luogu.org/problemnew/show/P2147 辉辉热 ...