日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

apizza+导出html文档,apizza导出为html后,从中提取api_name/api_path/api_method,保存到本地,方便根据接口名称得到接口路径与请求方法...

發布時間:2023/12/20 编程问答 30 豆豆

importreimportosdef open_file(file='c:/newcrm.html'):

f=open(file,'r',encoding='utf-8')returnfdefwrite_file():

list_api=[]

dict_api={}

file='../test/newcrm_source_api_name.txt'f=open_file()

f.seek(0,0)

str_api_name=re.findall('>.*',f.read()) #匹配接口名稱

f2=open_file()

f2.seek(0,0)

str_api_path=re.findall('請求地址:http://\S+\w|請求地址:http://\s',f2.read())#匹配接口路徑

f3=open_file()

f3.seek(0,0)

str_api_method=re.findall('

請求方式:.*

',f3.read())#匹配接口請求方式

dict_api['api_name']=str_api_name#將匹配后接口名稱插入字典s

dict_api["api_apth"]=str_api_path#將匹配后接口路徑插入字典

dict_api['api_method']=str_api_method#將匹配后接口請求方式插入字典

dict_api['api_name'].pop() #刪除最后一個

list_api.append(dict_api)#將字典添加至列表

#print('來源api_name個數:'+str(len(str_api_name)))

#print('來源api_path個數:'+str(len(str_api_path)))

#print('來源api_method個數:'+str(len(str_api_method)))

new_file=open(file,'w',encoding='utf-8')

new_file.write(str(list_api))

f.close()

f2.close()

f3.close()returnfile#print(dict_api)

#print(list_api)

def load_file(file=write_file()):# str_load=open(file,encoding='utf-8')

str_api=eval(str_load.read())

source_api_name=str_api[0]['api_name']

source_api_path=str_api[0]['api_apth']

source_api_method=str_api[0]['api_method']#print('來源api_name個數:'+str(len(source_api_name)))

#print('來源api_path個數:'+str(len(source_api_path)))

#print('來源api_method個數:'+str(len(source_api_method)))

returnsource_api_name,source_api_path,source_api_methoddefmodify_api_nameOrPathOrMethod():

source_file=load_file()

api_name=source_file[0]

api_path=source_file[1]

api_method=source_file[2]'''替換api_name'''api_name_to_str=''.join(api_name)

source_api_name=re.search('^>',api_name_to_str).group()#匹配字符串開頭

api_name_1=re.sub(source_api_name,'',api_name_to_str) #替換為空

source_api_name_2=re.search('

api_name_2=re.sub(source_api_name_2,' ',api_name_1)#替換為空格,為了防止匹配結果中帶有空格,這里多用幾個空格間隔

api_name_3=re.findall('\S+\s{4,}',api_name_2)

api_name_4=[]#存放去掉空格元素后的list

for name inapi_name_3:

name=name.rstrip()#去掉list元素中的空格

api_name_4.append(name)'''替換api_path'''api_path_to_str=''.join(api_path)

source_api_path=re.search('請求地址:',api_path_to_str).group()#匹配字符串開頭

api_path_1=re.sub(source_api_path,'',api_path_to_str) #替換為空

source_api_path_2=re.search('http://{{host}}',api_path_1).group()#匹配字符串結尾

api_path_2=re.sub(source_api_path_2,' ',api_path_1)#替換為空格

api_path_3=re.findall('\S+|\s{3,}',api_path_2)

api_path_4=[]for path inapi_path_3:if ' ' inpath:

path='api_path為空格:無效路徑,位置為列表第%s個元素'%(api_path_3.index(path))

api_path_4.append(path)else:

api_path_4.append(path)'''替換api_method'''api_method_to_str=''.join(api_method)

source_api_method=re.search('

請求方式:',api_method_to_str).group()#匹配字符串開頭

api_method_1=re.sub(source_api_method,'',api_method_to_str) #替換為空

source_api_method_2=re.search('

',api_method_1).group()#匹配字符串結尾

api_method_2=re.sub(source_api_method_2,' ',api_method_1)#替換為空格

api_method_3=re.findall('\S+',api_method_2)#寫入數據

list_api=[]

dict_api={}

dict_api['api_name']=api_name_4#將匹配后并處理完畢(去除空格)接口名稱插入字典

dict_api["api_apth"]=api_path_4#將匹配后并處理完畢(對路徑為空格的進行說明)接口路徑插入字典

dict_api['api_method']=api_method_3#將匹配后接口請求方式插入字典

list_api.append(dict_api)#將字典添加至列表

#print('最終api_name個數:'+str(len(api_name_4)))

#print('最終api_path個數:'+str(len(api_path_4)))

#print('最終api_method個數:'+str(len(api_method_3)))

new_file_name='../test/now_newCrm_api.data'new_file=open(new_file_name,'w',encoding='utf-8')

new_file.write(str(list_api))returnnew_file_namedefload_newFile():

new_file='../test/now_newCrm_api.data'

if notos.path.exists(new_file):

new_file=modify_api_nameOrPathOrMethod()

new_str_load=open(new_file,encoding='utf-8')

new_str_api=eval(new_str_load.read())

new_api_name=new_str_api[0]['api_name']

new_api_path=new_str_api[0]['api_apth']

new_api_method=new_str_api[0]['api_method']#print('來源api_name個數:'+str(len(new_api_name)))

#print('來源api_path個數:'+str(len(new_api_name)))

#print('來源api_method個數:'+str(len(new_api_name)))

count=0for a,b,c inzip(new_api_name,new_api_path,new_api_method):#if len(new_api_name)==5:

count+=1

if count<5:print(a,b,c)#write_file()#load_file()#test=modify_api_nameOrPathOrMethod()

load_newFile()

總結

以上是生活随笔為你收集整理的apizza+导出html文档,apizza导出为html后,从中提取api_name/api_path/api_method,保存到本地,方便根据接口名称得到接口路径与请求方法...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。