我有一个问题。 我有两个文件: getDetailsFromKP.js:
const nightmare = require('nightmare')({ show: false });
const cheerio = require('cheerio');
module.exports.getDetailsFromKP = async (kpID) => {
const url = `https://www.kinopoisk.ru/film/${ kpID }/`;
nightmare
.goto(url)
.wait('body')
.evaluate(() => {
return document.querySelector('body').innerHTML;
})
.end()
.then((result) => {
const $ = cheerio.load(result);
let genres = [];
$('[itemprop=genre]').children('a').each((i, element) => {
genres.push(`#${ $(element).text() }`);
});
return {
title: $('span.moviename-title-wrapper').text(),
orig_title: $('span.alternativeHeadline').text(),
description: $('div.brand_words.film-synopsys').text(),
image: $('a.popupBigImage').children('img').attr('src'),
rating: $('span.rating_ball').text(),
genres,
time: $('td.time').text(),
russia_ical: $('[data-ical-type=rus]').attr('data-ical-date'),
world_ical: $('[data-ical-type=world]').attr('data-ical-date')
}
})
.catch((error) => {
console.log(error);
})
};
和index.js
(async () => {
//const movie = await getMovieByPage(1);
const details = await getDetailsFromKP('694051');
console.log(details);
})();
index.js中的
async函数返回未定义。 我不知道哪里出了问题。我觉得我使用async / await的方式不正确。