Advertisement
dereksir

Untitled

Mar 7th, 2024
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (async () => {
  2.   //...
  3.     try {
  4.         //...
  5.  
  6.         // scroll to the bottom of the page
  7.         await autoScroll(page);
  8.  
  9.         // retrieve HTML content
  10.         const htmlContent = await page.content();
  11.         // parse HTML using Cheerio
  12.         const $ = cheerio.load(htmlContent);
  13.  
  14.         // extract desired data using Cheerio selectors
  15.         $('.post').each((index, element) => {
  16.             const title = $(element).find('h4').text().trim();
  17.             const price = $(element).find('h5').text().trim();
  18.             console.log(`item ${index + 1}: ${title}, ${price}`);
  19.         });
  20.  
  21.     } catch (error) {
  22.         console.error('Error:', error);
  23.     } finally {
  24.         await browser.close();
  25.   }
  26. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement