我在将诺言的结果返回到变量时遇到问题。对我有用的唯一方法是制作console.log,但这不是我想要的。
const getAnimeVideo = async (id: string, chapter: number) => {
const BASE_URL = `${url}${id}/${chapter}/`;
const browser = await puppeteer.launch() ;
const page = await browser.newPage();
await page.goto(BASE_URL);
const elementHandle = await page.$('.player_conte');
const frame = await elementHandle.contentFrame();
const video = await frame.$eval('#jkvideo_html5_api', el =>
Array.from(el.getElementsByTagName('source')).map(e => e.getAttribute("src")));
return video;
}
getAnimeVideo('tokyo-magnitude-80' , 1)
.then(res => console.log(res)); // It shows me the data correctly.
const T = getAnimeVideo('tokyo-magnitude-80' , 1)
.then(res => {
return res; //Promise { <pending> }
})