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里,然后编辑打印. 想 ...
随机推荐
- ionic 2 起航 控件的使用 客户列表场景(三)
我们来看看客户列表的搜索控件是怎么工作的吧. 1.打开customer.html <ion-content> <ion-searchbar [(ngModel)]="sea ...
- ajax请求总是返回error的问题
多半是因为返回值格式的问题,在后台返回的应与前台设定的值一直,不然就会进入error,会报404服务器错误,极有可能是后台返回的数据类型不对 public void exitSystem( HttpS ...
- 初识ListView - 定制ListView - 提升ListView运行效率
ListView绝对可以称得上是 Android 中最常用的控件之一,几乎所有的应用程序都会用到它.由于手机屏幕空间都比较有限,能够一次性在屏幕上显示的内容并不多,当我们的程序中有大量的数据需要展示的 ...
- 命令行启动mysql服务
在<计算机网络>课程中曾学过net命令,可以用于启动后台服务.在mysql中,net命令用于启动后台服务器进程mysqld,即后台服务. 不过,如果在普通用户模式下net start my ...
- MySQL访问
MySQL访问 1.介绍 python访问mysql数据库,需要安装mysql的python插件. 2.安装插件 通过pip命令安装mysql插件. # cmd>pip install PyMy ...
- hihoCoder #1044 : 状态压缩·一 (清垃圾)
题意: 某车厢有一列座位,共有n个位置,清洁工要在这n个位置上清垃圾,但是不能全部位置都清理,只能选择部分.选择的规则是,连续的m个位置内,不能够清理超过q个,也就是说从第1~m个位置最多可以清q个, ...
- hadoop balance均衡datanode存储不起作用问题分析
前段时间因为hadoop集群各datanode空间使用率很不均衡,需要重新balance(主要是有后加入集群的2台机器磁盘空间比较大引起的),在执行如下语句: bin/start-balancer.s ...
- coursera 算法二 week 1 wordnet
这周的作业可谓是一波三折,但是收获了不少,熟悉了广度优先搜索还有符号图的建立.此外还知道了Integer.MAX_VALUE. SAP: 求v和w的大概思路是对v和w分别广度优先搜索,然后遍历图中每一 ...
- libav(ffmpeg)简明教程(2)
距离上一次教程又过去了将近一个多月,相信大家已经都将我上节课所说的东西所完全消化掉了. 这节课就来点轻松的,说说libav的命令使用吧. 注:遇到不懂的或者本文没有提到的可以用例如命令后加 --hel ...
- World Wind Java开发之四——搭建本地WMS服务器(转)
在提供地理信息系统客户端时,NASA还为用户提供了开源的WMS Server 服务器应用:World Wind WMS Server.利用这个应用,我们可以架设自己的WMS服务并使用自己的数据(也支持 ...