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. Turing渲染着色器网格技术分析

    Turing渲染着色器网格技术分析 图灵体系结构通过使用 网格着色器 引入了一种新的可编程几何着色管道.新的着色器将计算编程模型引入到图形管道中,因为协同使用线程在芯片上直接生成紧凑网格( meshl ...

  2. pytest 给用例打标签

    1.给用例添加自定义标签命令:@pytest.mark.tagname     #tagname是自定义的标签名 import pytest class TestClass(): @pytest.ma ...

  3. 三、部署被监控主机-Zabbix Agent

    三.部署被监控主机-Zabbix Agent 1) 源码安装Zabbix agent软件 在2.100和2.200做相同操作(以zabbixclient web1为例). [root@zabbixcl ...

  4. 一文带你了解.Net互斥锁

    本文主要讲解.Net基于Threading.Mutex实现互斥锁 基础互斥锁实现 基础概念:和自旋锁一样,操作系统提供的互斥锁内部有一个数值表示锁是否已经被获取,不同的是当获取锁失败的时候,它不会反复 ...

  5. 腾讯TencentOS 十年云原生的迭代演进之路

    导语 TencentOS Server (又名 Tencent Linux 简称 Tlinux) 是腾讯针对云的场景研发的 Linux 操作系统,提供了专门的功能特性和性能优化,为云服务器实例中的应用 ...

  6. 你有一份经典SQL语句大全,请注意查收

    一.基础部分 1.创建数据库 CREATE DATABASE dbname 2.删除数据库 DROP DATABASE dbname 3.创建新表 CREATE TABLE tabname(col1 ...

  7. Redis面试连环问,快看看你能走到哪一步

    今天,我不自量力的面试了某大厂的java开发岗位,迎面走来一位风尘仆仆的中年男子,手里拿着屏幕还亮着的mac,他冲着我礼貌的笑了笑,然后说了句"不好意思,让你久等了",然后示意我坐 ...

  8. Qt实现网络聊天室(客户端,服务端)

    1. 效果演示 客户端 服务器 连接成功之后 2. 预备知识 如果不知道网络编程的可以去看我的上一篇文章C++网络编程 在Qt中,实现网络编程的方式比用C++或C实现要方便简单许多,因为Qt已经替我们 ...

  9. c++实现希尔密码

    实验名称: 希尔密码的实现(c++版;本文只以26个大写英文字符作为加密后的密文的可选项) 实验原理: 引用知识: 记 Zm={0,1,2,...,m-1} 定义1:设A为定义在集合Zm 上的n阶方阵 ...

  10. 25、mysqlreport(my.cnf)调优工具

    25.1.mysqlreport介绍: mysqlreport以很友好的方式显示 MySQL状态变.事实上,它几乎报告了所有的状态.不像 SHOW STATUS 只是在显示 了100多个状态值,mys ...