大鲲网发布项目列表树抓取
2018/07/09    标签: 大鲲网    抓取   

大鲲网发布项目列表树抓取

var tree=[];
    async function getTree(pId,level){
        fetchRst = await fetch('/base/getBaseLabel.json?req={"type":1,"parentId":'+pId+'}').then((rst)=>{return rst.text()}).then((rst)=>{return JSON.parse(rst)});
        if(typeof(fetchRst.labelList) !='undefined'){
            fetchRst.labelList.reduce((rst,last)=>{last['level'] = level; last['parentId'] = pId;tree.push(last); return tree},[]);
			level++;
			fetchRst.labelList.reduce((rst,last)=>{getTree(last.id,level);},{});
        }
    }
	getTree(0,0)
	setTimeout(()=>{console.log(JSON.stringify(tree))},2000);