Python 实现递归

import requests

def find_children(data, elements):
    children_found = []
    for items in data[elements]:
        children_found.append(items['name'])
        if items['children']:
            more_children = find_children(items, elements)
            for item in more_children:
                children_found.append(item)

    return children_found

headers = {'Content-type': 'application/json', xxxxx}
url = "https://xxxxx"
response = requests.get(url=url,headers=headers).json()

node_f = response["data"]["x x x"]["node"]

a = find_children(node_f, 'children')

print(a)
 
 
 
 
 
 
来源:https://www.jianshu.com/p/e8fcff19b3d6
posted @ 2022-07-20 14:16  林暗惊风  阅读(135)  评论(0)    收藏  举报