Advertisement
dereksir

Untitled

Feb 1st, 2024 (edited)
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { chromium } = require(“playwright”);
  2.  
  3. (async () => {
  4.     // Launch a browser
  5.     const browser = await chromium.launch();
  6.  
  7.     // Create a new browser context
  8.     const context = await browser.newContext();
  9.  
  10.     // Create a new page within the context
  11.     const page = await context.newPage();
  12.  
  13.     try {
  14.         // List of URLs to scrape
  15.         const urls = [“https://example.com”, “https://example.com/page2”, /* Add more URLs */];
  16.  
  17.         // Loop through the URLs
  18.         for (const url of urls) {
  19.             // Navigate to url
  20.             await page.goto(url);
  21.  
  22.             // Introduce a delay before the next request
  23.             await page.waitForTimeout(2000);
  24.         }
  25.  
  26.     } finally {
  27.         // Close the browser
  28.         await browser.close();
  29.     }
  30. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement