Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk7 min

How to Take Screenshots of URLs from a Text File with Bash

Use Bash to iterate through a URL list and let Playwright or Chrome render and capture each page. Includes CLI and API workflows, naming, reliability, and fixes.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Put one URL per line in a text file, then use Bash to read each line and a browser tool such as Playwright to render and save the page. For a quick batch, the Playwright CLI is convenient; for predictable filenames and per-URL error handling, run a Playwright script from Bash. The examples below skip blank lines and comments and save each capture under a unique name.

Prepare a URL list

Create urls.txt with one URL on each line:

https://example.com/
https://developer.chrome.com/
# Lines beginning with # are ignored
https://playwright.dev/

Install the Playwright CLI and the browser it needs by following the current Playwright CLI documentation. Installation steps can depend on your environment, so use the instructions there for your installed version.

As an Amazon Associate I earn from qualifying purchases.

Capture a batch with the Playwright CLI

This Bash loop reads the file literally, ignores blank lines and lines whose first non-space character is #, and assigns a distinct filename to each URL. It expects the Playwright CLI command playwright-cli to be installed and available on your PATH.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#!/usr/bin/env bash
set -u

input=${1:-urls.txt}
outdir=${2:-screenshots}
mkdir -p -- "$outdir"

line_no=0
while IFS= read -r url || [[ -n $url ]]; do
  [[ -z ${url//[[:space:]]/} ]] && continue
  [[ $url =~ ^[[:space:]]*# ]] && continue

  name=$(printf 'page-%04d.png' "$((++line_no))")
  printf 'Capturing %s -> %s/%sn' "$url" "$outdir" "$name"
  playwright-cli open "$url"
  playwright-cli screenshot --filename="$outdir/$name"
done < "$input"

Save it as capture.sh, then run bash capture.sh. To choose a different input file and output directory, run bash capture.sh my-urls.txt captures. The Playwright CLI workflow uses open <url> followed by screenshot; it supports explicit filenames and options including full-page and high-resolution capture. See the CLI reference for the exact options supported by your installed version.

#1 Best Overall

The loop is a practical starting point, not a production job runner. Its CLI session behavior may need adjustment for the version and environment you use. In particular, a failed navigation can interrupt the workflow or leave you without a useful screenshot; for repeatable batches, use the API pattern below to control browser lifetime and recover from individual failures.

Use the Playwright API for controlled batches

A small Playwright program is easier to extend with per-URL timeouts, error reporting, and a consistent browser lifecycle. Bash can still supply the file and launch the script. The core browser calls are page.goto() and page.screenshot(), as shown in the Playwright Page API reference.

For example, the following Node.js script reads a URL file, skips blank and comment lines, assigns filenames based on the original line number, records failures, and closes the browser even if a capture fails. Install Playwright and its browser according to the current Playwright instructions, then save this as capture.mjs:

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

const input = process.argv[2] ?? 'urls.txt';
const outdir = process.argv[3] ?? 'screenshots';
const lines = (await readFile(input, 'utf8')).split(/r?n/);
await mkdir(outdir, { recursive: true });

const browser = await chromium.launch({ headless: true });
try {
  const page = await browser.newPage({ viewport: { width: 1280, height: 800 } });
  for (let i = 0; i < lines.length; i++) {
    const url = lines[i].trim();
    if (!url || url.startsWith('#')) continue;

    const filename = path.join(outdir, `page-${String(i + 1).padStart(4, '0')}.png`);
    try {
      await page.goto(url, { waitUntil: 'load', timeout: 30000 });
      await page.screenshot({ path: filename });
      console.log(`Saved ${url} -> ${filename}`);
    } catch (error) {
      console.error(`Failed at line ${i + 1} (${url}): ${error.message}`);
    }
  }
} finally {
  await browser.close();
}

Run it directly with node capture.mjs urls.txt screenshots, or have Bash launch it:

#!/usr/bin/env bash
set -u
node capture.mjs "${1:-urls.txt}" "${2:-screenshots}"

This version uses one browser and one page for the batch. If you need pages isolated from one another, create a new page or browser context per URL. A navigation timeout is treated as a failure and logged; tune the timeout and navigation condition for sites that take longer or depend on client-side rendering. A successful load event does not guarantee every image or late-running widget has finished, so choose an appropriate wait condition for the site rather than assuming all pages behave alike.

Choose viewport, full-page, format, and resolution

  • Viewport capture: saves the visible browser area. The API example sets a 1280 by 800 CSS-pixel viewport.
  • Full-page capture: use the CLI’s --full-page option or the Page API screenshot option fullPage: true when you need the scrollable document rather than just the initial view.
  • Image format: the CLI offers PNG, JPEG, and WebP selection. In the Page API, the filename extension determines the image format; use a matching extension such as .png, .jpg, or .webp.
  • Resolution: the CLI documents a --hires option. In the API, screenshot scale choices and device scale settings affect output dimensions and file size. Consult the relevant CLI and Page API references for option syntax.

A full-page image can be very tall, while higher-resolution captures consume more disk space. Pick settings according to whether you need a readable archive, a viewport snapshot, or a visual comparison.

Rank #2
Dell Latitude 5420 14" FHD Business Laptop Computer, Intel Quad-Core i5-1145G7, 16GB DDR4 RAM, 256GB SSD, Camera, HDMI, Windows 11 Pro (Renewed)
  • 256 GB SSD of storage.
  • Multitasking is easy with 16GB of RAM
  • Equipped with a blazing fast Core i5 2.00 GHz processor.

Simple alternative: Chrome Headless

Chrome can capture a URL directly from the command line. For example:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
chrome --headless --screenshot --window-size=412,892 https://developer.chrome.com/

Chrome’s documented --screenshot behavior saves the image as screenshot.png in the current working directory. That fixed name makes a naïve loop unsafe: each invocation can overwrite the prior image. To preserve all captures, run each Chrome command from a separate output directory or rename the generated file after each successful run. See the Chrome Headless command-line reference for current options.

Reliability, repeatability, and cost

  • Check output per URL: ensure each expected filename exists and is non-empty; a command completing does not prove that the page rendered as intended.
  • Keep runs comparable: use the same operating system, browser version, viewport, settings, and headless mode for visual comparisons. Playwright notes that screenshot output can vary with browser and operating-system details and hardware; pixel-identical output across different environments is not guaranteed. See its screenshot comparison guidance.
  • Manage large lists: a single browser process avoids launching a browser for every URL. For very large jobs, consider controlled concurrency, but account for memory use and sites that limit request rates.
  • Use a local output directory: check available disk space, particularly for full-page or high-resolution images, and avoid reusing filenames if earlier captures must be retained.
  • Budget operational costs: Playwright and Chrome are browser automation options, but your batch still uses local compute, network access, and storage. The cited documentation does not establish a per-screenshot service price.

Troubleshooting

The CLI command is not found

Install the Playwright CLI using its current documentation and confirm that playwright-cli is on your PATH. The CLI and Playwright’s Node.js API may have different setup steps; use the matching installation guide.

The loop produces only one screenshot or overwrites files

Confirm that the loop creates a unique --filename for each input URL. If using Chrome Headless instead, its documented default is screenshot.png, so rename it after every capture or use a distinct working directory per URL.

A line is skipped or treated as an invalid URL

The examples intentionally ignore empty lines and comments beginning with # after optional whitespace. Check for accidental whitespace, missing URL schemes such as https://, or other malformed entries in the input file.

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

A screenshot is blank, incomplete, or missing late content

The page may need more time, a different navigation wait condition, or a site-specific selector wait. In the API script, adjust the timeout and navigation strategy, and consider waiting for a known element before capturing. No single wait condition fits every site.

Rank #3
15.6 Inch Win 11 Laptop Computer, N4020, 4GB DDR4 RAM, 128GB Storage | LPDDR4 RAM, 180° Lay-Flat, Dual-Band WiFi, Type-C PD Fast Charging, Thin & Lightweight for Students, Home & Office, Gray
  • WINDOWS 11 | STABLE PERFORMANCE: Powered by Intel Celeron N4020 processor and Windows 11 system, this laptop delivers stable performance for everyday computing tasks. It supports web browsing, online learning, document editing, email communication, and basic office work with optimized power efficiency, providing a practical and reliable experience for essential daily use for daily use.
  • 15.6” FHD IPS DISPLAY: Features a 15.6-inch Full HD IPS display with narrow bezels, offering wider viewing angles and clearer image details compared to standard panels. The improved screen-to-body ratio enhances visual experience for study, reading, document work, and video playback, making it suitable for both productivity and entertainment use.
  • 4GB DDR4 + 128GB eMMC STORAGE: Equipped with 4GB DDR4 memory and 128GB eMMC storage for everyday basics such as browsing, documents, email, and online learning platforms. The built-in TF card slot supports storage expansion up to 1TB, giving you more flexibility for files, photos, videos, and daily documents. TF card not included.
  • CONNECTIVITY & PORTS: Includes 1× TF card slot, 2× USB 3.2 Gen1 ports, and 2× full-featured Type-C ports (USB 3.2 Gen1). The Type-C ports support data transfer, charging, and video output, enabling flexible connection with external devices such as monitors, storage, and peripherals for daily work and study use.
  • LIGHTWEIGHT DESIGN | ONLINE COMMUNICATION: Designed with a slim, portable profile, this laptop is easy to carry for school, commuting, and travel. A built-in 1MP front camera supports online classes, video meetings, remote communication, and everyday conferencing. The 3300mAh battery works with the low-power system design to support practical daily use, while thermal optimization helps maintain quieter operation during extended tasks.

Some URLs fail but the batch should continue

Use the API version’s per-URL try/catch and log the failing line and URL. Avoid letting one navigation error terminate all later captures. Check whether the URL is reachable from the machine running the browser and whether the site presents a bot check or other access restriction.

Images differ between runs

Standardize the operating system, browser version, headless mode, viewport, and device scale settings. Dynamic page content can also change between navigations, so a screenshot workflow is not automatically a stable visual test.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

For an API call instead of managing a local browser, ScreenshotNeo returns a screenshot or PDF for a URL. See the ScreenshotNeo website and API documentation.

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.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo accepts cookie/consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; those steps can be turned off. Bot checks/CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.

Sign up for 1,000 free screenshots a month, with no card required.

Frequently Asked Questions

Can the URL file contain Windows-style line endings?

Yes. The Playwright API example splits on either LF or CRLF, and Bash’s read loop handles ordinary newline-delimited files.

Can I use the same batch workflow to save PDFs?

The local screenshot examples produce images. PDF capture requires a browser PDF workflow rather than the screenshot calls shown here.

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.

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
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair 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.