import requests
import json
import openpyxl
url_list=[
{'text':'证件类型','url':'https://open.italent.cn/api/Metadata/GetDataSource?_t=1686734008902&fieldName=IDType&metaName=TenantBase.EmployeeInformation&sourceName='},
{'text':'民族','url':'https://open.italent.cn/api/Metadata/GetDataSource?_t=1686732126783&fieldName=Nation&metaName=TenantBase.EmployeeInformation&sourceName='},
{'text':'籍贯','url':'https://open.italent.cn/api/Metadata/GetDataSource?_t=1686735867139&fieldName=Nationality&metaName=TenantBase.EmployeeInformation&sourceName='},
{'text':'政治面貌','url':'https://open.italent.cn/api/Metadata/GetDataSource?_t=1686734717459&fieldName=PoliticalStatus&metaName=TenantBase.EmployeeInformation&sourceName='},
{'text':'最高学历','url':'https://open.italent.cn/api/Metadata/GetDataSource?_t=1686734750835&fieldName=EducationLevel&metaName=TenantBase.EmployeeInformation&sourceName='},
]
for url_item in url_list:
res = requests.get(url_item['url'])
if res.status_code == 200:
text = json.loads(res.text)
info_dict_list=text['data']['items']
print(info_dict_list)
# 生成一个 Workbook 的实例化对象,wb即代表一个工作簿(一个 Excel 文件)
wb = openpyxl.Workbook()
# 获取活跃的工作表,ws代表wb(工作簿)的一个工作表
ws = wb.active
# 取集合第一个对象,循环键,保存到EXCEL
column = 65
row = 1
for title in info_dict_list[0]:
ws[chr(column)+str(row)] = title
column = column+1
# 循环集合,保存到EXCEL
column = 65
row = 2
for item in info_dict_list:
for val in item.values():
ws[chr(column)+str(row)] = val
column = column+1
column = 65
row = row+1
# 保存Excel
path='./test/北森数据字典/'+url_item['text']+'.xlsx'
print(path)
wb.save(path)
Python 调用接口
于 2023-06-14 18:14:51 首次发布