http://www.downza.cn/soft/11145.html PS下载地址
http://www.bejson.com/jsonviewernew/ JSON的在线视图
import requests
url = 'https://movie.douban.com'
url1 = 'https://search.douban.com/movie/subject_search'
r = requests.get(url='https://movie.douban.com')
paydata = {'search_text':'Teacher','cat':1002}
r = requests.get(url=url1,params=paydata)
print(r.status_code) #状态码
print(r.text) #响应内容
print(r.content.decode('utf')) #字节流 把字节转换为中文
print(r.url) #url
print(r.encoding) #编码格式
import requests
import json
url = 'https://www.lagou.com/jobs/positionAjax.json?needAddtionalResult=false'
headers = {
    'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
    'Cookie':'JSESSIONID=ABAAABAABFIAAACEBE8AD07641E9CDE63BF0812AA182306; __guid=237742470.3752759870354819600.1580823932255.3586; WEBTJ-ID=20200204214542-17010731db87d-018d0092af1e6a-454c092b-1049088-17010731db91a; _ga=GA1.2.1788274808.1580823946; _gid=GA1.2.1421117658.1580823946; user_trace_token=20200204214547-a60e97c9-4754-11ea-af23-5254005c3644; LGUID=20200204214547-a60e9b5c-4754-11ea-af23-5254005c3644; index_location_city=%E5%85%A8%E5%9B%BD; TG-TRACK-CODE=index_search; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%221701073f332163-0d4ab9c8e5f6be-454c092b-1049088-1701073f3331f%22%2C%22%24device_id%22%3A%221701073f332163-0d4ab9c8e5f6be-454c092b-1049088-1701073f3331f%22%7D; X_MIDDLE_TOKEN=60e32c1f76d7949967ac9ef5e5aaabef; lagou_utm_source=A; Hm_lvt_4233e74dff0ae5bd0a3d81c6ccf756e6=1580823946,1580824068,1580913010; Hm_lpvt_4233e74dff0ae5bd0a3d81c6ccf756e6=1580915924; SEARCH_ID=68e06e018ddc43b2a8d829f0e10c8855; monitor_count=33; X_HTTP_TOKEN=c8a95705e204e59a40175908510f64c31ff8f001a4; _gat=1; PRE_UTM=; PRE_HOST=; PRE_LAND=https%3A%2F%2Fwww.lagou.com%2Fjobs%2Flist%5F%25E8%2587%25AA%25E5%258A%25A8%25E5%258C%2596%25E6%25B5%258B%25E8%25AF%2595%2Fp-city%5F0%3F%26cl%3Dfalse%26fromSearch%3Dtrue%26labelWords%3D%26suginput%3D; LGSID=20200206104504-ce133552-e0ef-48b8-af92-9aa2182c2ed7; PRE_SITE=https%3A%2F%2Fwww.lagou.com%2Futrack%2FtrackMid.html%3Ff%3Dhttps%253A%252F%252Fwww.lagou.com%252Fjobs%252Flist%255F%2525E8%252587%2525AA%2525E5%25258A%2525A8%2525E5%25258C%252596%2525E6%2525B5%25258B%2525E8%2525AF%252595%252Fp-city%255F0%253F%2526cl%253Dfalse%2526fromSearch%253Dtrue%2526labelWords%253D%2526suginput%253D%26t%3D1580957097%26%5Fti%3D1; LGRID=20200206104504-58c5e35a-ca62-4bfa-a6b4-564bb611cc0e',
    'Referer':'https://www.lagou.com/jobs/list_%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95/p-city_0?&cl=false&fromSearch=true&labelWords=&suginput=',
    'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'
}
data = {
    'first':'false',
    'pn':2,
    'kd':'自动化测试',
    'sid':'8fc0bd4a8ae7471f8b48179e78ef804f'
}
r = requests.post(url=url,data=data,headers=headers,timeout=0.3)
print(r.status_code)
print(type(r.json()))
print(json.dumps(r.json(),indent=True,ensure_ascii=False))
post 中data和json的使用,主要看请求头中的 Content-Type类型 data = json.dumps(data)或者 json=data
print(r.json()['content']['positionResult']['result'][0]['companyFullName'])
cookie的处理案例
import requests
url = 'http://www.renren.com/ajaxLogin/login?1=1&uniqueTimestamp=202014161691'
def getheaders():
    headers = {
        'Content-Type':'application/x-www-form-urlencoded',
        'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
        # 'Cookie':'anonymid=k6agx27k-4y637m; depovince=GW; _r01_=1; JSESSIONID=abcCqJP9pvVyoaG_1Kzax; ick_login=5decb7b1-44f7-4e7f-9ab9-584be1318cb6; __guid=238633222.2841094300608286700.1580977055396.5442; taihe_bi_sdk_uid=fb8853833de6eb33167c9d33f92c8545; taihe_bi_sdk_session=ee8126229981f64001f01b1b123280c4; first_login_flag=1; ln_uact=18797815816; ln_hurl=http://hdn.xnimg.cn/photos/hdn221/20181215/2150/h_main_BQJL_13bc000f55f11986.jpg; loginfrom=null; springskin=set; jebe_key=750789ec-ee20-4f87-88af-ae4136fa7650%7C59d6a45b40f5eff03ceca5fd44f241d8%7C1580977144984%7C1%7C1580977144921; jebe_key=750789ec-ee20-4f87-88af-ae4136fa7650%7C59d6a45b40f5eff03ceca5fd44f241d8%7C1580977144984%7C1%7C1580977144941; vip=1; wp_fold=0; jebecookies=71d7a58a-12f3-410d-ab44-7f2e34ed3d86|||||; monitor_count=3'
    }
    return headers
def Data():
    data = {
        'email':'18797815816',
        'autoLogin':'true',
        'icode':'ST7T',
        'origURL':'http://www.renren.com/home',
        'domain':'renren.com',
        'key_id':1,
        'captcha_type':'web_login',
        'password':'71e92cbb2659c9c92a9797b193b889f1791cc51f3387f0fae3e6c71329e322a7',
        'rkey':'14bf33ff3fade143d5f83f99e09174f8',
        'f':''
    }
    return data
def login():
    r = requests.post(url=url,data=Data(),headers=getheaders())
    # print(r.content.decode('utf-8'))
    return r.cookies  
print(login())
def getProfile():
    #查看个人主页
    url = 'http://www.renren.com/969120248/profile'
    r = requests.get(url=url,cookies=login())
    print(r.text)
getProfile()
token的处理
处理的思路,产品登录成功后,取出token,给下一个请求参数传入token
Auth 鉴权的处理
import requests
from requests.auth import HTTPBasicAuth
r = requests.get(url='http://127.0.0.1:5000/v1/api/books',auth=HTTPBasicAuth('Admin','admin'))
print(r.json()['data'][0])
session 的处理思路
import requests
url = 'http://www.renren.com/ajaxLogin/login?1=1&uniqueTimestamp=202014161691'
def getheaders():
    headers = {
        'Content-Type':'application/x-www-form-urlencoded',
        'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
        # 'Cookie':'anonymid=k6agx27k-4y637m; depovince=GW; _r01_=1; JSESSIONID=abcCqJP9pvVyoaG_1Kzax; ick_login=5decb7b1-44f7-4e7f-9ab9-584be1318cb6; __guid=238633222.2841094300608286700.1580977055396.5442; taihe_bi_sdk_uid=fb8853833de6eb33167c9d33f92c8545; taihe_bi_sdk_session=ee8126229981f64001f01b1b123280c4; first_login_flag=1; ln_uact=18797815816; ln_hurl=http://hdn.xnimg.cn/photos/hdn221/20181215/2150/h_main_BQJL_13bc000f55f11986.jpg; loginfrom=null; springskin=set; jebe_key=750789ec-ee20-4f87-88af-ae4136fa7650%7C59d6a45b40f5eff03ceca5fd44f241d8%7C1580977144984%7C1%7C1580977144921; jebe_key=750789ec-ee20-4f87-88af-ae4136fa7650%7C59d6a45b40f5eff03ceca5fd44f241d8%7C1580977144984%7C1%7C1580977144941; vip=1; wp_fold=0; jebecookies=71d7a58a-12f3-410d-ab44-7f2e34ed3d86|||||; monitor_count=3'
    }
    return headers
def Data():
    data = {
        'email':'18797815816',
        'autoLogin':'true',
        'icode':'ST7T',
        'origURL':'http://www.renren.com/home',
        'domain':'renren.com',
        'key_id':1,
        'captcha_type':'web_login',
        'password':'71e92cbb2659c9c92a9797b193b889f1791cc51f3387f0fae3e6c71329e322a7',
        'rkey':'14bf33ff3fade143d5f83f99e09174f8',
        'f':''
    }
    return data
def login():
    s = requests.Session()
    r = s.post(url=url,data=Data(),headers=getheaders())
    # print(r.content.decode('utf-8'))
    return s  
login()
def getProfile():
    #查看个人主页
    url = 'http://www.renren.com/969120248/profile'
    r = login().get(url=url,cookies=login())
    print(r.text)
getProfile()
图片上传操作
import requests
url = 'http://upload.renren.com/upload.fcgi?pagetype=addpublishersingle&hostid=969120248&callback=window.parent.handlePhotoData&uploadid=profile_publisher_photo_1581055343406'
def getheaders():
    headers = {
        'Content-Type':'multipart/form-data;',
        'Cookie':'anonymid=k6agx27k-4y637m; depovince=GW; _r01_=1; taihe_bi_sdk_uid=fb8853833de6eb33167c9d33f92c8545; ln_uact=18797815816; ln_hurl=http://hdn.xnimg.cn/photos/hdn221/20181215/2150/h_main_BQJL_13bc000f55f11986.jpg; springskin=set; jebe_key=750789ec-ee20-4f87-88af-ae4136fa7650%7C59d6a45b40f5eff03ceca5fd44f241d8%7C1580977144984%7C1%7C1580977144921; _de=6B7940F5B97ED7B17DBB8F9AC51F78BA; p=f3b40f4c426a9ae54444d012b249304c8; ap=969120248; first_login_flag=1; t=88bddb94a692968e32e040a92f26bfb68; societyguester=88bddb94a692968e32e040a92f26bfb68; id=969120248; xnsid=e233e0a0; loginfrom=syshome; wp_fold=0; taihe_bi_sdk_session=b66e2aa58a8e974c83a9ab6696905589; XNESSESSIONID=606c5f9e7654',
        'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'
    }
    return headers
def Data():
    data = {
        'title':'',
        'upload':'提交',
        '__channel':'renren',
        'privacyParams':'{"sourceControl": 99}',
        'hostid':'969120248',
        'requestToken':'-71562601',
        '_rtk':'c77d08f1',
    }
    return data
files = {'file':('xx.png',open(r'C:\Users\lenovo\Desktop\sucai\xx.png','rb'),'image/png',{})}
r = requests.post(url=url,data=Data(),headers=getheaders(),files=files)
print(r.status_code)
print(r.content.decode('utf-8'))
文件的下载
import requests
import shutil
def headers():
    pass
def Data():
    pass
r = requests.post(url=url,headers,data=data,stream=True)
if r.status_code == 200:
    pass
postman
安装Newman 先安装node.js,把npm添加到环境变量中。
npm install newman --registry=https://registry.npm.taobao.org
newman run 拉钩网.postman_collection.json newman-reporter-html
login登录成功后是不是代表业务流程是对的?
不是,只是代表login的接口是对的。
接口测试的维度:
1.请求参数的边界值
2.请求参数为空
3.请求参数数据类型
4.请求&响应时间的验证
5.基本的业务流程,业务流程ok,前后端业务场景测试ok
不需要单独的验证数据库的数据是否正确
因为客户端向服务端发起请求获取数据,服务端链接到数据库,写SQL语句,然后返回需要的内容给客户端
500万请求数据,怎么断言数据,服务器会链接SQL语句,把消费的金额进行累计进行断言。

Python + Requests 知识点回顾的更多相关文章

  1. Python+pytest知识点回顾

    pip install pytest pytest 单元测试框架 pytest高于unittest测试框架 unittest测试类需要继承unittest.TestCase类 pytest不需要继承, ...

  2. Python + unittest知识点回顾

    postman 安装Newman 先安装node.js,把npm添加到环境变量中. npm install newman --registry=https://registry.npm.taobao. ...

  3. 零基础Python知识点回顾(一)

    如果你是小白,建议只要安装官网的python-3.7.0-amd64.exe 然后在电脑cmd命令提示符  输入检查是否已经安装pip,一般安装了python都会有的. >pip         ...

  4. 转载:python + requests实现的接口自动化框架详细教程

    转自https://my.oschina.net/u/3041656/blog/820023 摘要: python + requests实现的接口自动化框架详细教程 前段时间由于公司测试方向的转型,由 ...

  5. django知识点回顾与补充

    一.django知识点回顾 1.Cookie操作 - 客户端本地存储的键值对 2.Session操作 - 3.URL路由 - /index -> view.函数 4.MTV 5.View中返回方 ...

  6. python+requests接口自动化测试框架实例详解

    python+requests接口自动化测试框架实例详解   转自https://my.oschina.net/u/3041656/blog/820023 摘要: python + requests实 ...

  7. python爬虫知识点详解

    python爬虫知识点总结(一)库的安装 python爬虫知识点总结(二)爬虫的基本原理 python爬虫知识点总结(三)urllib库详解 python爬虫知识点总结(四)Requests库的基本使 ...

  8. python + requests实现的接口自动化框架详细教程

    前段时间由于公司测试方向的转型,由原来的web页面功能测试转变成接口测试,之前大多都是手工进行,利用postman和jmeter进行的接口测试,后来,组内有人讲原先web自动化的测试框架移驾成接口的自 ...

  9. 基于python+requests的简单接口测试

    在进行接口测试时,我们可以使用已有的工具(如:jmeter)进行,也可以使用python+requests进行.以下为简单的接口测试模板: 一.提取常用变量,统一配置 新建一个config.py文件, ...

随机推荐

  1. 多级中间表示概述MLIR

    多级中间表示概述MLIR MLIR项目是一种构建可重用和可扩展的编译器基础结构的新颖方法.MLIR旨在解决软件碎片,改善异构硬件的编译,显着降低构建特定于域的编译器的成本以及帮助将现有编译器连接在一起 ...

  2. 编译ONNX模型Compile ONNX Models

    编译ONNX模型Compile ONNX Models 本文是一篇介绍如何使用Relay部署ONNX模型的说明. 首先,必须安装ONNX包. 一个快速的解决方案是安装protobuf编译器,然后 pi ...

  3. Tomcat配置probe详细过程(步骤加截图)

    1.先下载probe.war包,点击probe.war进行下载:附上下载地址:https://github.com/psi-probe/psi-probe/releases 2.将probe.war包 ...

  4. postgresql无序uuid性能测试

    无序uuid对数据库的影响 由于最近在做超大表的性能测试,在该过程中发现了无序uuid做主键对表插入性能有一定影响.结合实际情况发现当表的数据量越大,对表插入性能的影响也就越大. 测试环境 Postg ...

  5. 【题解】将军令 Luogu P3942 (未完成)

    历史/落在/赢家/之手 至少/我们/拥有/传说 谁说/败者/无法/不朽 拳头/只能/让人/低头 念头/却能/让人/抬头 抬头/去看/去爱/去追 你心中的梦 将军令 题目描述 又想起了四月. 如果不是省 ...

  6. DOS命令行(1)——Windows目录与文件应用操作

    cd 1.使用cd快速切换到指定盘符与目录中 命令格式1:cd [/d] [<盘符>][<路径>] 或 chdir [/d] [<盘符>][<路径>] ...

  7. canvas绘制动画的技巧

    我们拿下图中的沿着线段轨迹移动的原点来举例,怎么来实现这个动画! 1)定义路径集合Path,里面规定关键坐标点如startPoint和endPoint,设置从startPoint移动到endPoint ...

  8. 海量数据Excel报表利器——EasyExcel(一 利用反射机制导出Excel)

    EasyExcel 写入(导出) 互联网的精髓就是共享,可以共享技术.共享经验.共享情感.共享快乐~ 很多年前就有这个想法了,从事IT行业时间也不短了,应该把自己工作和业余所学习的东西记录并分享出来, ...

  9. css实现相框效果

    <!DOCTYPE html><html> <head> <meta charset="utf-8"> <title>& ...

  10. 学会这些CSS技巧让你写样式更加丝滑

    目录 1,前言 1,calc() 2,min() 3,max() 4,clamp() 5,gap 6,writing-mode 1,前言 记录一些很好用的css属性 1,calc() calc()函数 ...