requests模块介绍:http://docs.python-requests.org/zh_CN/latest/index.html

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @File  : module_requests.py
# @Author: jing
# @Date  : 2019/1/24
# @Desc  :# -----requests模块------介绍
# 1、安装requests模块
# 打开cmd进入命令行模式—>输入pip insall requests—>回车
# 2、打开pycharm#导入 requests库
import requests
#登录接口地址
login_url='http://192.168.135.128:9999/futureloan/mvc/api/member/login'
#登录接口的参数,且请求的参数一般是放到字典里面
login_data={'mobilephone':'13417467890','pwd':'123456'}#发起一个get请求,并返回一个响应体
login_response=requests.get(login_url,login_data)
print('响应体是:',login_response)
# 响应体是: <Response [200]># Response里面包含:响应头headers,响应正文text,状态码status_code
print('登录的响应头是:',login_response.headers)  # 头是以字典格式存储
print('登录的响应正文是:',login_response.text)
print('登录的响应状态码是:',login_response.status_code)
print('获取json格式的响应正文:',login_response.json())
print('登录成功,返回的cookie是:',login_response.cookies)
print(login_response.cookies['JSESSIONID'])#cookies在取值时类似字典,用key
# 登录的响应头是: {'Content-Type': 'application/json;charset=UTF-8', 'Date': 'Tue, 01 Jan 2019 04:26:06 GMT', 'Set-Cookie': 'JSESSIONID=7486AD63E6D6B00473F1492956596BF7; Path=/futureloan/; HttpOnly, rememberMe=deleteMe; Path=/futureloan; Max-Age=0; Expires=Mon, 31-Dec-2018 04:26:06 GMT', 'Server': 'Apache-Coyote/1.1', 'Transfer-Encoding': 'chunked'}
# 登录的响应正文是: {"status":1,"code":"10001","data":null,"msg":"登录成功"}
# 登录的响应状态码是: 200
# 获取json格式的响应正文: {'status': 1, 'data': None, 'msg': '登录成功', 'code': '10001'}
# 登录成功,返回的cookie是: <RequestsCookieJar[<Cookie JSESSIONID=7C5BAE48A7499671EACA1ED59A3C7839 for 192.168.135.128/futureloan/>]>
# 347D82692A898B8223BED33D2D0F8B77# request 里面包含:URL,请求方式,请求正文,请求头
print('登录的请求地址是:',login_response.request.url)
print('登录的请求头是:',login_response.request.headers)
print('登录的请求正文是:',login_response.request.body)
# 登录的请求地址是: http://192.168.135.128:9999/futureloan/mvc/api/member/login?mobilephone=13417467890&pwd=123456
# 登录的请求头是: {'Accept-Encoding': 'gzip, deflate', 'User-Agent': 'python-requests/2.21.0', 'Accept': '*/*', 'Connection': 'keep-alive'}
# 登录的请求正文是: None-------------get请求,参数附在url后面,没有请求体body#发起一个post请求
import requests
msg1='登录成功'
responsesdata=requests.post(url=login_url,data=login_data)
print('登录以json格式返回的响应正文是:',responsesdata.json())
print('post登录的请求地址是:',login_response.request.url)
print('post登录的请求正文是:',login_response.request.body)
#判断接口执行结果是否通过
if responsesdata.json()['msg']=='登录成功':print('通过')

  

转载于:https://www.cnblogs.com/yhms/p/10136167.html

requests模块介绍相关推荐

  1. 爬虫之requests模块介绍

    爬虫之requests模块介绍 requests文档http://docs.python-requests.org/zh_CN/latest/index.html      [文档中包括的快速上手要精 ...

  2. python requests_Python爬虫之requests模块

    # requests模块 知识点: 掌握 headers参数的使用 掌握 发送带参数的请求 掌握 headers中携带cookie 掌握 cookies参数的使用 掌握 cookieJar的转换方法 ...

  3. python网络爬虫系列(四)——requests模块

    requests模块 知识点: 掌握 headers参数的使用 掌握 发送带参数的请求 掌握 headers中携带cookie 掌握 cookies参数的使用 掌握 cookieJar的转换方法 掌握 ...

  4. 全程干货,requests模块与selenium框架详解

    requests模块 前言: 通常我们利用Python写一些WEB程序.webAPI部署在服务端,让客户端request,我们作为服务器端response数据: 但也可以反主为客利用Python的re ...

  5. 爬虫 requests 模块

    requests 模块 介绍 使用requests可以模拟浏览器的请求, 比起之前用到的urllib,requests模块的api更加便捷(本质就是封装了urllib3) ps: requests库发 ...

  6. Python网络爬虫(三. Requests模块)

    Requests 模块 首先一个简单的requests请求例子(直接复制到PyCharm即可运行): import requestsurl = "https://www.baidu.com& ...

  7. 爬虫中requests模块(一)

    一.requests模块介绍 1.requests模块的作用 发送http请求,获取响应数据. 2.安装 pip/pip3 install requests 3.发送get请求 导入requests模 ...

  8. Pycharm中导入requests模块详解

    这篇文章主要介绍了教你如何在Pycharm中导入requests模块,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下 1.找到python的安装路径: 如果忘 ...

  9. python requests模块_Python 爬虫教程 requests 模块

    经过 前边文章<简单Python爬虫教程 (一)>.简单Python爬虫教程 (二)两篇文章的学习,能写一些比较简单的爬虫了,但是还不够,这一篇文章主要介绍Requests模块,reque ...

  10. 爬虫 - requests模块

    基于GET请求 1.基本请求 import requests response=requests.get('http://dig.chouti.com/') print(response.text) ...

最新文章

  1. MSSQL事务开发指南
  2. 四大科技巨头跟随者众 智能家居市场容量可观
  3. 三维重建:PNG格式详解-与LibPNG使用
  4. FPGA常用总线IIC 与SPI选择策略
  5. 设置Mysql5.6允许外网访问详细流程
  6. java泛型为类类型_Java泛型:仅定义为返回类型的通用类型
  7. 软件、硬件版本号命名规范
  8. python办公自动化pdf下载_最全总结 | 聊聊 Python 办公自动化之 PDF(上)
  9. 计算机联锁维修管理机,计算机联锁试卷
  10. 计算机网络启动项,怎样设置电脑启动项_怎么设置电脑开机启动项-win7之家
  11. ax.contour绘制等值线图时报错:The following kwargs were not used by contour: ‘color‘
  12. python reserve函数_Python reversed函数及用法
  13. windows安装Rocket因为JAVAHOME空格导致找不到加载类问题
  14. java非主流火星文输入法_我爱火星文_火星文输入法
  15. Spring Boot整合ActiveMQ及场景举例(点对点模式、订阅模式)
  16. HTML基础学习记录
  17. 一个向上帝买了挂的男人
  18. 诛仙3el服务器位置,【诛仙3风吟】虚拟机镜像一键服务端+配套客户端+青萝+EL编辑器+GM工具+启动说明...
  19. 国产LoRa技术?ZETA相比LoRa有哪些优势?
  20. 你只知道@Value?设置server.port就能定义端口号是如何实现的?springboot读取配置文件的多种方式以及源码解析

热门文章

  1. 支持10秒自毁的新芯片
  2. 最新SMB僵尸网络利用了7个NSA工具,而WannaCry只用了两个……
  3. Jenkins实现生产环境部署文件的回滚操作(Windows)
  4. httping的使用介绍
  5. android surfaceview view 区别
  6. GPIO驱动实例:操作LED开关
  7. 推荐系统的常用算法概述
  8. 考前突击!等级考试高分攻略!(整理版)
  9. photo player 显示 ☞ 列表选中项的处理
  10. 从物理页面的争抢看linux内核内存管理