for(let i = 0;i<256;i++){ const sres = await getIndex(i); } function createMovie1(parr){ let movie1 = {}; parr.forEach(v=>{ if(v.substr(0,"译 名".length)=="译 名"){ movie1.yiname = v; } if(v.substr(0,"片 名".length)=="片 名"){ movie1.name = v; } if(v.substr(0,"年 代".length)=="年 代"){ movie1.year = v; } if(v.substr(0,"产 地".length)=="产 地"){ movie1.where = v; } if(v.substr(0,"产 地".length)=="产 地"){ movie1.where = v; } if(v.substr(0,"导 演".length)=="导 演"){ movie1.direct = v; } if(v.substr(0,"主 演".length)=="主 演"){ movie1.actor = v; } if(v.substr(0,"简 介".length)=="简 介"){ movie1.jianjie = v; } }); return movie1; } const url2 = 'http://localhost/f2.html'; async function getMovieFromUrl(url){ console.log(url) const sres = await superagent.get(url).charset('gbk'); let html = sres.text, $ = cheerio.load(html, { decodeEntities: false }), //用cheerio解析页面数据 obj = {}; let text=''; $("p").each((index, element) => { let $text = $(element).text(); text=text+$text; }); $("p img").each((index, element) => { let $imgurl = $(element).attr("src"); console.log($imgurl) }); let parr = text.split('◎') let movie1 = createMovie1(parr); console.log(movie1); } getMovieFromUrl(url2)