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里,然后编辑打印. 想 ...
随机推荐
- cms-后台eazyui搭建
1.引入eazyUi需要的js 2.布局:上.下.左.中 <%@ page language="java" contentType="text/html; char ...
- [转载]正则表达式参考文档 - Regular Expression Syntax Reference.
正则表达式参考文档 - Regular Expression Syntax Reference. [原创文章,转载请保留或注明出处:http://www.regexlab.com/zh/regref. ...
- hdu-1874 畅通工程续---模板题
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1874 题目大意: 求起点到终点的最短距离 解题思路: 注意重边,其他的就是模板 #include&l ...
- codeforces 1114C
题目连接 : https://codeforces.com/contest/1114/problem/C 题目大意:给一个整数n(1e18>=n>=0),和一个整数k(1e12>=k ...
- DLM分布式锁的实现机制
1.AST简介 DLM进程(LMON.LMD)之间的跨实例通信是使用高速互联上的IPC层实现的.为了传递锁资源的状态,DLM使用了异步陷阱(AST),它在操作系统处理程序例程中实现为中断.纯粹主义者可 ...
- 安装软件出现缺少vcruntime140dll的解决方法
转自:http://jingyan.baidu.com/article/49711c617e4000fa441b7c92.html 首先下载vc++2015,注意自己系统是32位还是64位的,下载对应 ...
- MySql-8.0.12 安装教程随笔
下载地址: https://www.mysql.com/downloads/ 现在最下边的社区版本,也就是免费版本 之后我们会看到有两个选择的下载,一个为zip压缩包格式,一个是Install版本,个 ...
- css中如何把鼠标变成手
css中鼠标放上去变成手型怎么设置:其实就是一个属性的问题, css的cursor属性 cursor:pointer; 其实这个属性我也记了很多,到现在都容易拼写错误,不过好在编辑器有提示. defa ...
- tomcat服务器用Servlet类查找磁盘文件上的Json信息,如果匹配则在浏览器上显示出该条内容的全部信息
package com.swift; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.IOE ...
- JS时间格式和时间戳的相互转换
时间戳转化为日期的方式 ; var newDate = new Date(); newDate.setTime(timestamp * ); // Mon May 28 2018 console.lo ...