0

I am using puppeeteer to scrape a site and have the following code

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();
  });
}

And I get the following errors

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)

It looks like I argument elementPath is not recognised by the document.querySelectorAll for reason.

Is there an issue with scope visibility?

neo-technoker
  • 369
  • 2
  • 8
  • 26

0 Answers0