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. 【.NET 与树莓派】温度/湿度传感器——SHT30

    SHT3XX 系列的传感,常见的有三种:SHT 30.SHT 31.SHT 35.其中,比较便宜性价比较愉快的是 SHT 30. DHT 11 模块也是检测温度.湿度的,但SHT 11 使用的不是我们 ...

  2. 狂神说Mybatis笔记

    环境说明: jdk 8 + MySQL 5.7.19 maven-3.6.1 IDEA 学习前需要掌握: JDBC MySQL Java 基础 Maven Junit 第一节:入门 什么是MyBati ...

  3. noip模拟8[星际旅行·砍树·超级树·求和]

    也不能算考得好,虽然这次A了一道题,但主要是那道题太简单了,没啥成就感,而且有好多人都A掉了 除了那一道,其他的加起来一共拿了25pts,这我能咋办,无奈的去改题 整场考试的状态并不是很好啊,不知道是 ...

  4. Python编解码问题与文本文件处理

    编解码器 在字符与字节之间的转换过程称为编解码,Python自带了超过100种编解码器,比如: ascii(英文体系) gb2312(中文体系) utf-8(全球通用) latin1 utf-16 编 ...

  5. 宝,我今天CR了,C的什么R? 走过场的CR

    原创:猿天地(微信公众号ID:cxytiandi),欢迎分享,转载请保留出处. CodeReview我相信目前很多公司都会有这么一个流程,关键是这个流程有没有用就很难讲.主要还是取决于你对CR的理解以 ...

  6. 入门Kubernetes - .Net Core 运行

    前言: 之前文章 对Kubernetes 的一些基础概念及在windows下的环境搭建,接下来把.Net Core 运行到Kubernetes 中,在实际的操作中,对Kubernetes 的进一步学习 ...

  7. JWT原理实现代码

    JWT学习文章: 第一篇:JWT原理 第二篇:JWT原理实现代码 上一篇学习了JWT的基本理论,这一篇将根据原理进行代码实现. 要想实现jwt的加密解密,要先生成一个SecurityKey,大家可以在 ...

  8. kubelet之volume manager源码分析

    kubernetes ceph-csi分析目录导航 基于tag v1.17.4 https://github.com/kubernetes/kubernetes/releases/tag/v1.17. ...

  9. 『心善渊』Selenium3.0基础 — 16、Selenium对iframe表单的操作

    目录 1.什么是iframe表单 2.iframe表单操作流程 3.iframe表单操作常用方法 (1)进入表单 (2)多表单切换 4.表单操作示例 1.什么是iframe表单 实际上就是HTML页面 ...

  10. 创建Akamai cdn api授权

    注:通过Akamai Cli purge和通过Akamai API进行刷新之前,都要事先创建类似于如下的刷新的凭据,这两种刷新方式所创建的凭据是相同的. 目的:创建Akamai CDN API授权以便 ...