1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ''' 根据HTML标签内容,生成测试json数据. ''' import re import json html='''<el-table-column prop="NAME" label="姓名" width="120"></el-table-column> <el-table-column prop="AGE" label="年龄"></el-table-column>''' if __name__ == '__main__': result=re.sub(r'(.*prop=")|(" label.*)','',html) lists=[] for index in range(1,4): dicts={} for item in result.split("\n"): if item: dicts[item]=f'{item}{index}' lists.append(dicts) print(json.dumps(lists,indent=4)) |