apizza导出为html后,从中提取api_name/api_path/api_method,保存到本地,方便根据接口名称得到接口路径与请求方法
import re
import os def open_file(file='c:/newcrm.html'):
f=open(file,'r',encoding='utf-8')
return f def write_file():
list_api=[]
dict_api={}
file='../test/newcrm_source_api_name.txt'
f=open_file()
f.seek(0,0)
str_api_name=re.findall('>.*</h3>',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('<p>请求方式:.*</p>',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()
return file
# 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)))
return source_api_name,source_api_path,source_api_method def modify_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('</h3$',api_name_1).group()#匹配字符串结尾
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 in api_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 in api_path_3:
if ' ' in path:
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('<p>请求方式:',api_method_to_str).group()#匹配字符串开头
api_method_1=re.sub(source_api_method,'',api_method_to_str) #替换为空
source_api_method_2=re.search('</p>',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))
return new_file_name def load_newFile():
new_file='../test/now_newCrm_api.data'
if not os.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=0
for a,b,c in zip(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后,从中提取api_name/api_path/api_method,保存到本地,方便根据接口名称得到接口路径与请求方法的更多相关文章
- 微信小程序导出当前画布指定区域的内容并生成图片保存到本地相册(canvas)
最近在学小程序,在把当前画布指定区域的内容导出并生成图片保存到本地这个知识点上踩坑了. 这里用到的方法是: wx.canvasToTempFilePath(),该方法作用是把当前画布指定区域的内容导出 ...
- jmeter接口参数化获取tocken后保存批量保存在本地
jmeter目录结构如下: 1,读取文件配置的ID提取tocken 2,CSV 数据文件设置,第一个为文件目录,第二个为参数化的参数名. 3,正则表达式提取tocken 4,BeanShell Pos ...
- IDEA导出jar包后运行报错 找不到或无法加载主类
开发工具:IDEA16 运行环境:ubuntu 问题:根据网上的Idea导出jar包的方法,将我的项目导出jar包后运行报错:找不到或无法加载主类. 为了找到这个原因,我重新搭建了一个测试例子,在 ...
- 【Jmeter】jmeter提取response中的返回值,并保存到本地文件--BeanShell后置处理器
有个需求,需要在压测环境中,创建几十万的账号数据,然后再根据创建结果,查询到某些账号信息. 按照之前我的做法,直接Python调用API,然后再数据库查询: 但是近期所有开发人员的数据库访问权限被限制 ...
- 以流方式读写文件:文件菜单打开一个文件,文件内容显示在RichTexBox中,执行复制、剪切、粘贴后,通过文件菜单可以保存修改后的文件。
MainWindow.xaml文件 <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation&q ...
- Windows已遇到关键问题,将在一分钟后自动重新启动,请立即保存工作
Windows已遇到关键问题,将在一分钟后自动重新启动,请立即保存工作 1. 把电脑右下角网络断开 2.同时按 "WIN+R" 打开“运行”命令窗口 输入“cmd”命令,按回车键“ ...
- DISCUZ站点DIY后,导致DIY功能失效,无法在前台删除已创建的DIY功能解决的方法
DISCUZ站点DIY后.导致DIY功能失效,无法在前台删除已创建的DIY功能解决的方法.这是一个常常会遇到的问题.在程序调试过程中常常的会遇到这种问题.这里提供一个自己常常使用的解决的方法,供遇到这 ...
- 把演讲人的桌面、头像、声音合成后推送到 指定的直播流平台上; 录制电脑桌面、摄像头头像、声音保存为本地视频; 适用于讲课老师、医生等演讲内容保存为视频; 提供PPT嵌入Winform/WPF解决方案,Winform/WPF 中嵌入 office ppt 解决方案
提供PPT嵌入Winform/WPF解决方案,Winform/WPF 中嵌入 office ppt 解决方案 Winform/WPF 中嵌入 office ppt(powerpoint)解决方案示: ...
- javascript下用ActiveXObject控件替换word书签,将内容导出到word后打印第1/2页
由于时间比较紧,没多的时候去学习研究上述工具包,现在用javascript操作ActiveXObject控件,用替换word模板中的书签方式解决. 最近有需求将数据导出到word里,然后编辑打印. 想 ...
随机推荐
- 360、IE等浏览器对bootstrap的影响
笔者开发的web程序部署上线后发现,bootstrap的菜单不显示,开发时候用chrome没有发现问题,在360浏览器上跑,发现360默认的是兼容模式,切换到极速模式就能够显示菜单了. 但是这样的用户 ...
- JavaScript_HTML DEMO_3_节点
创建新的HTML元素 删除已有的HTML元素 <body> <div id="div1"> <p id="p1">这是一个段 ...
- linux 命令——48 watch (转)
watch是一个非常实用的命令,基本所有的Linux发行版都带有这个小工具,如同名字一样,watch可以帮你监测一个命令的运行结果,省得你一遍遍的手动运行.在Linux下,watch是周期性的执行下个 ...
- bzoj4393: [Usaco2015 Dec]Fruit Feast
题意: T,A,B.T是上限.A和B可以随意吃但是不能超过T.有一次将吃的东西/2的机会.然后可以继续吃,不能超过T.问最多可以吃多少. =>我们先处理不能/2可以吃到哪些.然后弄个双指针扫一扫 ...
- URL Schemes 不能识别和不能跳转的原因
在app跳转的过程中 需要设置url schemes后,但是设置完后,却不能识别, (测试方式:URL scheme + ://)在浏览器中打开,如果能打开app,就是能跳转 今天遇到了一个坑爹的问题 ...
- python剑指offer 合并两个排序的链表
题目描述 输入两个单调递增的链表,输出两个链表合成后的链表,当然我们需要合成后的链表满足单调不减规则. # -*- coding:utf-8 -*- # class ListNode: # def _ ...
- MySQL的入门与使用,sqlyog对数据库,表和数据的管理
MySQL的入门 1.到mysql官网下载. 2.安装mysql软件(一定要放到英文路径下) 3.使用 验证是否成功 将mySQL的bin路径添加到系统环境变量Path中 打开dos命令窗口 Wind ...
- C# 运用DirectoryInfo类和FileInfo类
DirectoryInfo类和FileInfo类的基类都是FileSystemInfo类,这个类是一个抽象类,也就是说你不可以实例化该类,只能通过继承产生其子类并实例化其子类.然而你却可以运用由该类定 ...
- servlet层调用biz业务层出现浏览器 500错误,解决方法 dao数据访问层 数据库Util工具类都可能出错 通过新建一个测试类复制代码逐步测试查找出最终出错原因
package com.swift.jztk.servlet; import java.io.IOException; import javax.servlet.ServletException; i ...
- iOS 中push和pop到底系统做了些什么事
iOS中的push和pop是一个很常用的视图切换方法,他们是成对出现的, 简而言之,push就是压栈,pop就是出栈! [self.navigationController pushViewContr ...