我正在使用puppeeteer抓取网站,并显示以下代码
scrapeMoviesGeneric({
URL: "https://villagecinemas.com.au/events/indian-cinema",
elementPath: "ul.slider-list li.theme div.movie-name"
});
function scrapeMoviesGeneric({ URL, elementPath }) {
console.log(elementPath);
puppeteer.launch().then(async browser => {
const page = await browser.newPage();
await page.goto(URL);
const title = await page.title();
console.log(title);
const movies = await page.evaluate(() =>
Array.from(document.querySelectorAll(elementPath)).map(movie =>
movie.innerText.trim()
)
);
console.log(`movies ${movies}`);
await browser.close();
});
}
我收到以下错误消息
Cinemas | Where Movies Mean More
(node:6456) UnhandledPromiseRejectionWarning: Error: Evaluation failed: ReferenceError: ep is not defined
at __puppeteer_evaluation_script__:1:42
at ExecutionContext.evaluateHandle (C:\dev\sandbox\movie-scraper\node_modules\puppeteer\lib\ExecutionContext.js:106:13)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
-- ASYNC --
at ExecutionContext.<anonymous> (C:\dev\sandbox\movie-scraper\node_modules\puppeteer\lib\helper.js:144:27)
at ExecutionContext.evaluate (C:\dev\sandbox\movie-scraper\node_modules\puppeteer\lib\ExecutionContext.js:58:31)
at ExecutionContext.<anonymous> (C:\dev\sandbox\movie-scraper\node_modules\puppeteer\lib\helper.js:145:23)
at Frame.evaluate (C:\dev\sandbox\movie-scraper\node_modules\puppeteer\lib\FrameManager.js:439:20)
看来我的论据 elementPath 不能被document.querySelectorAll识别。
范围可见性有问题吗?