python之使用request模块发送post和get请求
import requests
import json #发送get请求并得到结果
# url = 'http://api.nnzhp.cn/api/user/stu_info?stu_name=小黑马 '#请求接口
# req = requests.get(url)#发送请求
# print(req.text)#获取请求,得到的是json格式
# print(req.json())#获取请求,得到的是字典格式
# print(type(req.text))
# print(type(req.json())) #发送post请求,注册接口
# url = 'http://api.nnzhp.cn/api/user/user_reg'
# data = {'username':'mpp0130','pwd':'Mp123456','cpwd':'Mp123456'}
# req = requests.post(url,data)#发送post请求,第一个参数是URL,第二个参数是请求数据
# print(req.json()) #入参是json
# url = 'http://api.nnzhp.cn/api/user/add_stu'
# data = {'name':'mapeipei','grade':'Mp123456','phone':15601301234}
# req = requests.post(url,json=data)
# print(req.json()) #添加header
# url = 'http://api.nnzhp.cn/api/user/all_stu'
# header = {'Referer':'http://api.nnzhp.cn/'}
# res = requests.get(url,headers=header)
# print(res.json()) # 添加cookie
# url = 'http://api.nnzhp.cn/api/user/gold_add'
# data = {'stu_id':231,'gold':123}
# cookie = {'niuhanyang':'7e4c46e5790ca7d5165eb32d0a895ab1'}
# req = requests.post(url,data,cookies=cookie)
# print(req.json()) #上传文件
# url = 'http://api.nnzhp.cn/api/file/file_upload'
# f = open(r'E:\besttest\te\python-mpp\day7\练习\11.jpg','rb')
# r = requests.post(url,files={'file':f})
# users_dic = r.json()
# print(users_dic) # 下载文件
# url = 'http://www.besttest.cn/data/upload/201710/f_36b1c59ecf3b8ff5b0acaf2ea42bafe0.jpg'
# r = requests.get(url)
# print(r.status_code)#获取请求的状态码
# print(r.content)#获取返回结果的二进制格式
# fw = open('mpp.jpg','wb')
# fw.write(r.content)
# fw.close() #把浏览器页面下载到本地 保存网页,可以理解为简单的爬虫工具
url='http://www.nnzhp.cn/archives/630'
r = requests.get(url)
f = open('nnzhp.html','wb')
f.write(r.content)
f.close()
python之使用request模块发送post和get请求的更多相关文章
- python用httplib模块发送get和post请求
在python中,模拟http客户端发送get和post请求,主要用httplib模块的功能. 1.python发送GET请求 我在本地建立一个测试环境,test.php的内容就是输出一句话: 1 e ...
- python中的request模块
本文转自:https://www.cnblogs.com/ydy11/p/8902631.html(版权归属原作者,因觉得写得非常好,故引用) python模块之request模块的理解 reques ...
- python - 怎样使用 requests 模块发送http请求
最近在学python自动化,怎样用python发起一个http请求呢? 通过了解 request 模块可以帮助我们发起http请求 步骤: 1.首先import 下 request 模块 2.然后看请 ...
- Python接口测试-使用requests模块发送GET请求
本篇主要记录下使用python的requests模块发送GET请求的实现代码. 向服务器发送get请求:无参数时:r = requests.get(url)带params时:r = requests. ...
- Python接口测试-使用requests模块发送post请求
本篇主要记录下使用python的requests模块发送post请求的实现代码. #coding=utf-8 import unittest import requests class PostTes ...
- python flask的request模块以及在flask编程中遇到的坑
一.首先来讲讲遇到的坑: 1.linux下package的打包引用: """ 路径结构如下: ./project ./bin ./api ""&quo ...
- python 爬虫 基于requests模块发起ajax的post请求
基于requests模块发起ajax的post请求 需求:爬取肯德基餐厅查询http://www.kfc.com.cn/kfccda/index.aspx中指定某个城市地点的餐厅数据 点击肯德基餐厅查 ...
- python 爬虫 基于requests模块发起ajax的get请求
基于requests模块发起ajax的get请求 需求:爬取豆瓣电影分类排行榜 https://movie.douban.com/中的电影详情数据 用抓包工具捉取 使用ajax加载页面的请求 鼠标往下 ...
- python中安装request模块
使用命令行(cmd)进入到python安装目录下的Scripts文件夹(也可以先进入目标文件夹然后在文件路径上打开cmd回车即可) 在命令行中输入pip install requests,等待安装完成 ...
随机推荐
- break 用法
// break 在循环中的功能测试 # include <stdio.h> int main(void){ int i, j; for (i = 0; i<3; ++i) { j ...
- OpenWrt inittab
OpenWrt 启动时会执行 rc.d/ 下的脚本. 这篇文章 介绍了启动脚本里的规则. K50dropbear -> ../init.d/dropbear K85odhcpd -> .. ...
- Web 监听器
什么事web 监听器? Servlet规范中定义的一种特殊类 用于监听ServletContext.HttpSession和ServletRequest等象的创建与销毁的事件 用监听域对象的属性发生修 ...
- Linux下编译安装源码包软件 configure ,make, make install, make test/check, make clean
http://www.360doc7.net/wxarticlenew/541275971.html 一.什么是源码包软件? 顾名思义,源码包就是源代码的可见的软件包,基于Linux和BSD系统的软件 ...
- iOS 声明属性关键字的总结
atomic: 原子操作(原子性是指事务的一个完整操作,操作成功就提交,反之就回滚. 原子操作就是指具有原子性的操作)在objective-c 属性设置里面 默认的就是atomic ,意思就是 set ...
- SpringMVC配置环境中一般用的jar包
配置SpringMVC需要把这些jar包加入lib目录下 下载地址,复制到地址栏.回车即可下载 http://files.cnblogs.com/files/QW-lzm/SpringMVC----. ...
- Python小练习_将数据库中表数据存到redis里
# ##练习:将xxx数据库中my_user表中数据存到redis里面# 分析: pymysql.json.redis# 1.连接数据库,查到数据库里面所有的数据,游标类型要用pymysql.curs ...
- g00 网站说明
最近在做dns tunnel检测,发现了一堆类似这样的域名:c-6rtwjumjzx7877x24uwjkjwjshjx78x2eywzx78yjx2ehtr.g00.medicinenet.com ...
- Balancing Act(树的重心)
传送门 Balancing Act Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14070 Accepted: 593 ...
- CodeForces 1103C. Johnny Solving
题目简述:给定简单(无自环.无重边)连通无向图$G = (V, E), 1 \leq n = |V| \leq 2.5 \times 10^5, 1 \leq m = |E| \leq 5 \time ...