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,保存到本地,方便根据接口名称得到接口路径与请求方法的更多相关文章

  1. 微信小程序导出当前画布指定区域的内容并生成图片保存到本地相册(canvas)

    最近在学小程序,在把当前画布指定区域的内容导出并生成图片保存到本地这个知识点上踩坑了. 这里用到的方法是: wx.canvasToTempFilePath(),该方法作用是把当前画布指定区域的内容导出 ...

  2. jmeter接口参数化获取tocken后保存批量保存在本地

    jmeter目录结构如下: 1,读取文件配置的ID提取tocken 2,CSV 数据文件设置,第一个为文件目录,第二个为参数化的参数名. 3,正则表达式提取tocken 4,BeanShell Pos ...

  3. IDEA导出jar包后运行报错 找不到或无法加载主类

    开发工具:IDEA16 运行环境:ubuntu 问题:根据网上的Idea导出jar包的方法,将我的项目导出jar包后运行报错:找不到或无法加载主类.   为了找到这个原因,我重新搭建了一个测试例子,在 ...

  4. 【Jmeter】jmeter提取response中的返回值,并保存到本地文件--BeanShell后置处理器

    有个需求,需要在压测环境中,创建几十万的账号数据,然后再根据创建结果,查询到某些账号信息. 按照之前我的做法,直接Python调用API,然后再数据库查询: 但是近期所有开发人员的数据库访问权限被限制 ...

  5. 以流方式读写文件:文件菜单打开一个文件,文件内容显示在RichTexBox中,执行复制、剪切、粘贴后,通过文件菜单可以保存修改后的文件。

    MainWindow.xaml文件 <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation&q ...

  6. Windows已遇到关键问题,将在一分钟后自动重新启动,请立即保存工作

    Windows已遇到关键问题,将在一分钟后自动重新启动,请立即保存工作 1. 把电脑右下角网络断开 2.同时按 "WIN+R" 打开“运行”命令窗口 输入“cmd”命令,按回车键“ ...

  7. DISCUZ站点DIY后,导致DIY功能失效,无法在前台删除已创建的DIY功能解决的方法

    DISCUZ站点DIY后.导致DIY功能失效,无法在前台删除已创建的DIY功能解决的方法.这是一个常常会遇到的问题.在程序调试过程中常常的会遇到这种问题.这里提供一个自己常常使用的解决的方法,供遇到这 ...

  8. 把演讲人的桌面、头像、声音合成后推送到 指定的直播流平台上; 录制电脑桌面、摄像头头像、声音保存为本地视频; 适用于讲课老师、医生等演讲内容保存为视频; 提供PPT嵌入Winform/WPF解决方案,Winform/WPF 中嵌入 office ppt 解决方案

    提供PPT嵌入Winform/WPF解决方案,Winform/WPF 中嵌入 office ppt 解决方案 Winform/WPF 中嵌入 office ppt(powerpoint)解决方案示: ...

  9. javascript下用ActiveXObject控件替换word书签,将内容导出到word后打印第1/2页

    由于时间比较紧,没多的时候去学习研究上述工具包,现在用javascript操作ActiveXObject控件,用替换word模板中的书签方式解决. 最近有需求将数据导出到word里,然后编辑打印. 想 ...

随机推荐

  1. 问题 M: 克隆玩具

    题目描述 你只有一个A类型玩具,现在有个有两种功能的机器:1. 加工一个A类型的玩具能够再得到一个A类型的玩具和一个B类型的玩具.2. 加工一个B类型的玩具,能得到两个B类型的玩具. 问经过多次加工之 ...

  2. FETCH - 用游标从查询中抓取行

    SYNOPSIS FETCH [ direction { FROM | IN } ] cursorname where direction can be empty or one of: NEXT P ...

  3. 2017.12.22 Java序列化中你不知道的事(一)

    Java 序列化简介 Java 对象序列化是 JDK 1.1 中引入的一组开创性特性之一,用于作为一种将 Java 对象的状态转换为字节数组,以便存储或传输的机制,以后,仍可以将字节数组转换回 Jav ...

  4. 逗塔战争TD新人入门图文攻略

    逗塔战争TD新人入门图文攻略   <逗塔战争TD>是一张基于DOTA改编的塔防TD,很多玩家都很喜欢这张图,新手玩家怎么快速上手这张图呢?这张图的玩法和基本规则并不难,下面就为大家带来新人 ...

  5. java定义一个Circle类,包含一个double型的radius属性代表圆的半径,一个findArea()方法返回圆的面积

    需求如下:(1)定义一个Circle类,包含一个double型的radius属性代表圆的半径,一个findArea()方法返回圆的面积. (2)定义一个类PassObject,在类中定义一个方法pri ...

  6. window10启用administrator 和启用组策略编辑器

    1,启用administrator账户 net user administrator /active:yes 2,启用组策略编辑器    新建一个文本文件.把下面代码粘贴进去.修改后缀名为.cmd  ...

  7. node基础

    javascript window gulp ---- 前端工程构建工具 webpack ---- 前端工程构建工具 java Python php:后台 本地电脑,服务器 node 本地或服务端运行 ...

  8. SummerVocation_Learning--java的String类运用

    题目: 编写一个程序,输出一个字符串中的大写字母数,小写字母数,及其它字母数. 思路1: 可以先遍历整个字符串,在判断每个字符的类型. public class TestString { public ...

  9. 线程池是什么?Java四种线程池的使用介绍

    使用线程池的好处有很多,比如节省系统资源的开销,节省创建和销毁线程的时间等,当我们需要处理的任务较多时,就可以使用线程池,可能还有很多用户不知道Java线程池如何使用?下面小编给大家分享Java四种线 ...

  10. mysql 查询 7天内的数据

    SELECT ID,SERVICE FROM new_schedules_spider_full WHERE SERVICE = 'WSA2' and date_sub(curdate(), inte ...