方式一:--------------------------------------------------------------------------------------------------------------------------------------
只存在單個復制單個請求時:(但是如果當前接口集存在很多個請求時這樣操作就需要重復很多次了)
1、打開對應的請求界面的code,並選擇python-requests類型代碼格式
2、可復制出代碼到自己本地編輯器
方式二:----------------------------------------------------------------------------------------------------------------------
postman中的接口請求集中存在多個請求時: 循環判斷請求接口
1、選中某個接口集,然后選擇Export
默認導出為一個json文件,所以默認導出就可以了
2、打開查看這個導出的接口json文件.
------> 實際上在 python編輯器內就是:將json文件進行序列化、反序列化的操作進行讀取並循環請求;
3、python寫一個循環讀取及請求:
(讀取的是導出的json文件中的內容,即:實際接口請求的返回的內容)
import json
import requests
def readjson(): #定義一個讀取文件的方法
return json.load(open('xxxx.json','r'))['item'] #返回讀取的內容:以json格式返回讀取的內容
def get_method(): #定義一個獲取請求為get或者是POST的方法,並返回結果
for item in readjson(): #對json文件中的item進行循環遍歷 if item['request']['method']=='GET': #遍歷到這個item['requests']['method']下如果請求方式為get r=requests.request( method=item['request']['method'],#將遍歷到的這個賦給method url=item['request']['url']['raw']) #將遍歷到的這個賦給url print(r.json()) elif item['request']['method']=='POST': #遍歷到這個下,如果請求方式為post r=requests.request( method=item['request']['method'], #將循環遍歷到的這個賦給method url=item['request']['url']['raw'], #將循環遍歷到的這個賦給url json=json.loads(item['request']['url']['raw'])) print(r.json()) if __name__ == "__main__": #最后實例調用 get_method()