我正在尝试从视频服务中获取数据。我有这样的 puppeteer 代码(我在这里得到了数据):
const getListVideos = async (url) => {
try {
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.setRequestInterception(true)
page.on('request', interceptedRequest => {
// fetch data from this URL
if (interceptedRequest._url.includes('mineCode')) {
return fetch(interceptedRequest._url)
.then(res => res.json())
.then(res => {
// console.log(res) => has data JSON here
return res
})
} else {
interceptedRequest.continue()
}
})
await page.goto(url)
await page.waitForTimeout(151)
await browser.close()
} catch (error) {
console.log(error)
}
}
然后我在其他文件上有一个用于路由器调用的函数
export const videosFromAuthorURL = async (req, res) => {
await getListVideos(req.body.url)
.then(resp => {
console.log(resp) // data is not passed here, undefined
})
}
数据未定义,我不确定它有什么问题。你能帮我解决吗?
谢谢