October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

Puppeteer से कई URLs के website screenshots एक साथ कैसे लें

Puppeteer में एक browser से कई URLs के screenshots लें—क्रमवार या सीमित workers के साथ, अलग फ़ाइलों और प्रति-URL त्रुटि प्रबंधन सहित।

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Node.js में Puppeteer से URL की सूची के screenshots लेने के लिए एक browser खोलें, हर URL पर अलग page बनाएँ, page तैयार होने की प्रतीक्षा करें और हर screenshot को अलग फ़ाइल में सहेजें। छोटी सूची के लिए क्रमवार loop सबसे सरल है; बड़ी सूची के लिए सीमित संख्या में workers चलाएँ—कितने workers सुरक्षित होंगे, यह आपके सिस्टम और लक्षित वेबसाइटों पर निर्भर है।

शुरू करने से पहले

यह उदाहरण Puppeteer के मौजूदा आधिकारिक दस्तावेज़ में दिखाए गए API पैटर्न पर आधारित है; इसे व्यक्तिगत रूप से चलाकर परीक्षण किया हुआ नहीं माना जाना चाहिए। आधिकारिक दस्तावेज़ में वर्तमान संस्करण 25.12.0 दर्ज है। Puppeteer screenshots guide के अनुसार screenshots के लिए Page.screenshot() इस्तेमाल करें।

As an Amazon Associate I earn from qualifying purchases.

Node.js प्रोजेक्ट में Puppeteer इंस्टॉल करें और ES modules सक्षम रखें। नीचे का उदाहरण मानता है कि package.json में "type": "module" है। यदि यह सेटिंग नहीं है, तो या तो इसे जोड़ें या अपने प्रोजेक्ट के CommonJS ढाँचे के अनुसार import बदलें। साथ ही, screenshot लिखने से पहले screenshots फ़ोल्डर मौजूद होना चाहिए।

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

छोटी URL सूची: क्रमवार screenshots

क्रमवार तरीका एक समय में एक page काम में रखता है, इसलिए इसे समझना और त्रुटियों का पता लगाना आसान है। यह runnable उदाहरण फ़ोल्डर बनाता है, हर URL के लिए viewport तय करता है, HTTP status जाँचता है, अलग PNG फ़ाइल लिखता है और किसी एक URL की विफलता के बाद भी अगली URL पर जाता है।

import puppeteer from 'puppeteer';
import { mkdir } from 'node:fs/promises';

const urls = [
  'https://example.com',
  'https://example.org',
];

await mkdir('screenshots', { recursive: true });
const browser = await puppeteer.launch();
const results = [];

try {
  for (const [index, url] of urls.entries()) {
    const outputPath = `screenshots/page-${index + 1}.png`;
    let page;

    try {
      page = await browser.newPage();
      await page.setViewport({ width: 1365, height: 900 });

      const response = await page.goto(url, {
        waitUntil: 'load',
        timeout: 30_000,
      });

      if (response && response.status() >= 400) {
        throw new Error(`HTTP ${response.status()} for ${url}`);
      }

      await page.screenshot({ path: outputPath, fullPage: true });
      results.push({ url, outputPath, status: 'saved' });
    } catch (error) {
      results.push({
        url,
        outputPath,
        status: 'failed',
        error: error.message,
      });
    } finally {
      if (page) await page.close();
    }
  }
} finally {
  await browser.close();
}

console.log(results);

फ़ाइल नाम में URL को सीधे न जोड़ें: URL में ऐसे अक्षर हो सकते हैं जो फ़ाइल पथ के लिए उपयुक्त न हों। उदाहरण में स्थिर क्रमांक इस समस्या से बचाता है। यदि नाम इंसानों के लिए पढ़ने योग्य चाहिए, तो URL से सुरक्षित slug बनाएँ और टकराव से बचने के लिए क्रमांक या अन्य स्थिर पहचान भी जोड़ें।

सभी URLs के लिए एक साथ काम करना

क्रमवार loop एक समय में एक URL संभालता है। अधिक URLs पर सीमित worker pool बनाकर कई navigation को overlap किया जा सकता है, लेकिन इससे browser और मशीन पर संसाधन की माँग तथा वेबसाइटों पर अनुरोधों का दबाव बढ़ सकता है। Puppeteer की API कई pages बनाने की सुविधा देती है, लेकिन दस्तावेज़ कोई सार्वभौमिक सुरक्षित worker संख्या या throughput सीमा नहीं बताते। इसलिए संख्या को अपने लक्ष्य और मशीन पर सावधानी से तय करें; कोई तय संख्या हर परिस्थिति के लिए सही नहीं है।

एक browser साझा रखें और workers को URL के अलग-अलग indices दें। हर task पूरी तरह settle होने के बाद ही browser बंद करें। नीचे सीमित workers का उदाहरण है; WORKERS को अपने संसाधनों और वेबसाइटों के अनुरूप समायोजित करें।

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import puppeteer from 'puppeteer';
import { mkdir } from 'node:fs/promises';

const urls = [
  'https://example.com',
  'https://example.org',
  'https://example.net',
];
const WORKERS = 3;

await mkdir('screenshots', { recursive: true });
const browser = await puppeteer.launch();
const results = new Array(urls.length);
let nextIndex = 0;

async function worker() {
  while (true) {
    const index = nextIndex++;
    if (index >= urls.length) return;

    const url = urls[index];
    const outputPath = `screenshots/page-${index + 1}.png`;
    let page;

    try {
      page = await browser.newPage();
      await page.setViewport({ width: 1365, height: 900 });
      const response = await page.goto(url, {
        waitUntil: 'load',
        timeout: 30_000,
      });

      if (response && response.status() >= 400) {
        throw new Error(`HTTP ${response.status()} for ${url}`);
      }

      await page.screenshot({ path: outputPath, fullPage: true });
      results[index] = { url, outputPath, status: 'saved' };
    } catch (error) {
      results[index] = {
        url,
        outputPath,
        status: 'failed',
        error: error.message,
      };
    } finally {
      if (page) await page.close();
    }
  }
}

try {
  await Promise.all(
    Array.from({ length: Math.min(WORKERS, urls.length) }, () => worker()),
  );
} finally {
  await browser.close();
}

console.log(results);

यह worker संख्या प्रदर्शन का दावा नहीं है। छोटी सूची पर क्रमवार तरीका पर्याप्त हो सकता है; parallel काम तभी बढ़ाएँ जब आपको इसकी ज़रूरत हो और आप संसाधन उपयोग तथा असफलताओं पर नज़र रख सकें।

सही screenshot और page readiness चुनें

Navigation कब पूरा मानें

Page.goto() को ऐसे URL की आवश्यकता होती है जिसमें https:// जैसा scheme हो। इसका default wait condition load है और दस्तावेज़ित default timeout 30 सेकंड है। waitUntil और timeout को इच्छित दृश्य स्थिति और साइट के व्यवहार के अनुसार चुनें; navigation event अपने-आप यह साबित नहीं करता कि client-side app का आवश्यक हिस्सा तैयार है। आधिकारिक विकल्पों के लिए Page.goto() API देखें।

यदि screenshot से पहले किसी खास app हिस्से का दिखना ज़रूरी है, तो navigation के बाद उस हिस्से के selector का इंतज़ार करें। हर साइट के लिए एक ही wait condition सही नहीं होती।

await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 30_000 });
await page.waitForSelector('[data-page-ready="true"]', { timeout: 10_000 });

यह selector केवल उदाहरण है—इसे उस वेबसाइट के वास्तविक readiness संकेत से बदलें। इंतज़ार की lifecycle शर्तों के बारे में PuppeteerLifeCycleEvent API देखें।

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Viewport, पूरी लंबाई या चुना हुआ हिस्सा

Viewport dimensions navigation से पहले सेट करें, जब वे page layout को प्रभावित करते हों। साधारण screenshot configured viewport दिखाता है; fullPage: true पूरे document को कैप्चर करने के लिए है। यदि केवल क्षेत्र चाहिए, तो clip का उपयोग करें। Screenshot विकल्पों में path, fullPage, clip, type और quality शामिल हैं; quality PNG पर लागू नहीं होती। विवरण ScreenshotOptions API में है।

Best Value
The SQL Programming Language: .
  • Used Book in Good Condition
// Viewport screenshot
await page.screenshot({ path: 'screenshots/viewport.png' });

// पूरी लंबाई
await page.screenshot({ path: 'screenshots/full.png', fullPage: true });

// चुना हुआ क्षेत्र
await page.screenshot({
  path: 'screenshots/region.png',
  clip: { x: 0, y: 0, width: 800, height: 500 },
});
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Pages, cookies और अलग browser state

एक Browser instance में कई Page instances हो सकते हैं और हर page का अपना viewport हो सकता है। सामान्य browser.newPage() उपयोग साझा browser context के भीतर pages बनाता है; यदि jobs को अलग cookies या local storage चाहिए, तो अलग BrowserContexts बनाकर उनमें pages बनाएँ। BrowserContext storage को अलग रखने के लिए है—इसे हर स्थिति में आवश्यक न मानें। देखें BrowserContext API।

आम त्रुटियाँ और उनके समाधान

  • Invalid URL या navigation error: URL में https:// या http:// जैसा scheme जोड़ें और जाँचें कि string खाली या गलत ढंग से बनी नहीं है।
  • Timeout: साइट धीमी हो सकती है या चुनी गई readiness condition पूरी नहीं हुई। केवल ज़रूरत होने पर timeout बढ़ाएँ, या किसी उपयुक्त lifecycle condition और app-specific selector का इंतज़ार करें।
  • 404 या 500 पर screenshot फिर भी बन गया: Puppeteer के headless shell व्यवहार में मान्य HTTP status जैसे 404 या 500 अपने-आप navigation exception न दें। यदि असफल status पर screenshot नहीं चाहिए, तो response.status() जाँचें, जैसा ऊपर के उदाहरण में है। कभी-कभी response नहीं मिलता; इसलिए उदाहरण response मौजूद होने की जाँच भी करता है। विवरण Page.goto() API में है।
  • Screenshot फ़ाइल नहीं लिखी गई: output directory मौजूद है या नहीं जाँचें; उदाहरण इसे mkdir से बनाता है। यह भी सुनिश्चित करें कि अलग URLs एक ही output path पर न लिखें।
  • एक साइट विफल होने पर पूरी batch रुक जाती है: हर URL के काम को अलग try/catch में रखें और परिणाम में URL, त्रुटि और output path दर्ज करें।
  • Parallel चलाने पर संसाधन दबाव या अस्थिरता: workers घटाएँ और आवश्यकता के अनुसार क्रमवार execution पर लौटें। आधिकारिक दस्तावेज़ कोई निश्चित सुरक्षित concurrency संख्या नहीं देते।

Or skip the browser setup

यदि स्थानीय browser और URL-by-URL error handling स्वयं नहीं सँभालना चाहते, तो ScreenshotNeo एक GET request से screenshot या PDF देता है। इसकी API documentation: ScreenshotNeo docs.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

ScreenshotNeo capture से पहले cookie/consent banners स्वीकार कर और 60 से अधिक ज्ञात consent platforms, newsletter popups तथा chat widgets हटा सकता है; इन चरणों को बंद भी किया जा सकता है। Bot checks/CAPTCHAs, blank pages, timeouts और failed loads पर शुल्क नहीं लगता, और response में X-Page-Verdict तथा X-Billed headers बताते हैं कि क्या हुआ। AI agents के लिए इसका MCP server take_screenshot, get_page_info और capture_pdf tools देता है। Free plan में बिना card के 1,000 screenshots प्रति माह हैं; paid plans $5 में 3,000 से शुरू होते हैं।

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

ScreenshotNeo पर मुफ़्त साइन अप करें।

Frequently Asked Questions

क्या Puppeteer एक browser instance में कई pages खोल सकता है?

हाँ। एक Browser instance में कई Page instances हो सकते हैं; हर page का viewport अलग सेट किया जा सकता है।

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.