ScreenshotNeo

BlogHow-to

How to Capture Scheduled Screenshots of Indian Railway Booking Pages

Use Playwright to capture a public railway page, then schedule the script. Learn safe capture choices, setup, troubleshooting, and what to check before recurring use.

By the ScreenshotNeo team4 October 20269 min read

You can capture a public Indian railway webpage on a schedule by writing a small Playwright script that opens the page and saves a screenshot, then configuring your computer or an approved job runner to launch that script at the times you choose. The script performs the capture; the scheduler starts the script. This guide covers public pages only. It does not automate sign-in, ticket booking, CAPTCHA, payment, or other access controls.

Check permission before making this recurring. IRCTC’s published terms describe the site as for personal and non-commercial use and restrict copying or reproducing site information without permission. Its privacy policy also limits access or downloads to personal and non-commercial use and describes session logging and traveller information. The reviewed text does not expressly settle whether a private recurring screenshot of a public page is permitted. Do not assume it is authorized; for recurring, high-volume, commercial, or redistributed captures, ask IRCTC for permission or seek qualified advice. IRCTC terms · IRCTC privacy policy

1. Choose a public page and capture size

Use a page that is publicly accessible without signing in and does not expose passenger details, a PNR, payment information, or a personal journey plan. Do not put credentials into the script or reuse an authenticated browser session for this task.

Capture shape Use it when Trade-off
Viewport You need the visible area at one fixed screen size. Smaller and focused, but content below the fold is omitted.
Full page You need the complete scrollable page in one image. Can create a very tall file; text may be hard to read when viewed at fit-to-screen size.
Selected element You need one chart, notice, or other page component. Requires a stable CSS selector and the element must be present when captured.

Playwright supports viewport, full-page, and selected-element screenshots saved to a file. See the Playwright screenshot documentation.

2. Install Playwright

Use a supported, maintained Node.js release on the machine that will run the schedule. Create a project directory, initialize it, and install Playwright and its browser:

mkdir railway-page-capture
cd railway-page-capture
npm init -y
npm install playwright
npx playwright install chromium

Keep the project and browser installation on the same machine or runner that will execute the scheduled job. The exact browser installation requirements can vary by operating system; consult Playwright’s installation guide if the browser does not start.

3. Write a timestamped capture script

Save this as capture.mjs. Replace the example URL with the public page you have permission to capture. The script uses a fixed viewport, waits for the page’s load event and a short settling period, and saves a unique PNG each time. It does not enter credentials or interact with booking controls.

import { chromium } from 'playwright';
import { mkdir } from 'node:fs/promises';
import path from 'node:path';

const targetUrl = 'https://www.indianrail.gov.in/';
const outputDir = path.resolve('screenshots');
const viewport = { width: 1440, height: 1000 };

await mkdir(outputDir, { recursive: true });
const browser = await chromium.launch({ headless: true });

try {
  const page = await browser.newPage({ viewport });
  page.setDefaultNavigationTimeout(45000);
  await page.goto(targetUrl, { waitUntil: 'load', timeout: 45000 });

  // Allow brief client-side rendering to settle. Adjust only for the public
  // page's normal rendering; do not try to defeat a challenge or access control.
  await page.waitForTimeout(1500);

  const timestamp = new Date().toISOString().replaceAll(':', '-');
  const filename = path.join(outputDir, `railway-page-${timestamp}.png`);
  await page.screenshot({ path: filename, fullPage: false });
  console.log(`Saved ${filename}`);
} finally {
  await browser.close();
}

Run it once manually before scheduling:

node capture.mjs

Inspect the image. Confirm that it contains only the public information you intended to retain. The example URL is a starting point; choose the specific public page you need and verify the site’s current terms first.

4. Adjust what the screenshot captures

Full-page screenshot

Change the screenshot call to:

await page.screenshot({ path: filename, fullPage: true });

Full-page capture records the scrollable page. Pages that load content only when scrolled can require extra care: a screenshot does not guarantee that every lazy-loaded item has appeared. Avoid repeatedly scrolling or triggering interactions if the page responds with a challenge or block.

Capture one element

Use a selector for a public element that exists on the page:

const panel = page.locator('main');
await panel.waitFor({ state: 'visible', timeout: 15000 });
await panel.screenshot({ path: filename });

Replace main with the intended CSS selector. If the selector matches nothing, matches multiple unintended elements, or the element is hidden, the capture may fail or show the wrong area. Inspect the page structure and use a specific stable selector; do not use selectors to automate booking or get around access controls.

Wait for a known page state

If a public page renders a particular heading after navigation, wait for it rather than choosing an arbitrary long delay:

await page.getByRole('heading', { name: 'Public page heading' }).waitFor({
  state: 'visible',
  timeout: 15000
});
await page.screenshot({ path: filename, fullPage: true });

Replace the example heading with text actually present on the page. If the page is static, waiting for the normal load event may be enough. Avoid polling aggressively; a modest schedule is easier on the site and less likely to encounter automated-traffic controls.

5. Schedule the script

Choose a local operating-system scheduler or an approved hosted runner. Configure its timezone explicitly, and make sure the machine or runner is available at the scheduled time. The scheduler should invoke the same command that worked manually, with the project directory and Node.js environment set correctly.

  • Local computer: The project and screenshot files stay under your control, but the computer must be on, awake, and connected at capture time.
  • Hosted runner: It may run while your computer is off, but you must check its approved-use rules, runtime and browser support, file retention, access controls, and storage location.
  • Timezone: Set the desired timezone explicitly. Daylight-saving changes can shift a local-time schedule where applicable.
  • Output: Use a persistent, restricted folder or approved storage. Some hosted jobs discard local files after the run unless you configure storage.

Scheduler setup differs by operating system and runner, and no one scheduler is required by Playwright. Follow the current manual for the scheduler you use. First run the exact scheduled command manually from its configured working directory, then confirm a new timestamped image appears at the expected time.

6. Protect the captured files and keep the environment consistent

  • Restrict folder access and retain only images you need.
  • Review a capture before sharing it. Remove or avoid anything showing names, account details, PNRs, journey plans, or payment information.
  • Keep the operating system, Playwright browser version, viewport, browser settings, and headless or headed mode consistent when comparing images. Rendering can differ with the host OS, browser version, settings, hardware, power source, and headless mode, as Playwright’s visual comparison guidance explains.
  • Stop the job if the site presents a CAPTCHA, challenge, block, login prompt, or booking interaction. Do not solve or evade it.

7. Troubleshoot common failures

Symptom Likely cause What to do
Executable doesn't exist or browser launch fails Chromium was not installed for this Playwright setup, or the scheduled environment uses a different project. Run npx playwright install chromium in the project environment and verify the scheduler’s working directory and runtime.
Navigation timeout The page is slow, unreachable, or waiting on resources that do not settle. Check that the public URL loads normally in a browser. Use a reasonable timeout for navigation; do not retry rapidly or treat a challenge as a transient error to bypass.
Screenshot is blank or incomplete Client rendering has not finished, a selector is wrong, or content appears only after scrolling. Wait for a specific visible element and inspect the output. Use full-page mode only when the complete page is appropriate and available.
Works manually but not on schedule The machine is asleep, timezone differs, environment variables or working directory are missing, or files are written somewhere unexpected. Use an absolute project/output path where practical, set the scheduler timezone and environment, keep the runner available, and inspect its logs.
Challenge, CAPTCHA, or access denied appears The site is applying an anti-automation or anti-fraud control, or the activity is not allowed. Stop capture. Do not automate a solution, change identity to evade controls, or continue against a block. Ask the site about permitted access if a legitimate recurring need exists.
Images differ between runs Page content, time, viewport, browser version, OS, or rendering mode changed. Keep the capture environment stable and record the timestamp. Some page variation is expected and is not necessarily a script defect.

Permission and anti-automation limits

IRCTC’s official terms and privacy policy contain restrictions relevant to copying or downloading site material, but the reviewed sources do not give a definitive answer about private periodic screenshots of public pages. The safest course is to verify current terms and ask IRCTC before recurring, high-volume, commercial, or redistributed capture. Store screenshots privately and minimize retention.

The Press Information Bureau, Government of India, has described CAPTCHA and time-based checks intended to prevent fraudulent or automated booking. Those reports are not a complete or current technical specification. Do not use this workflow to book tickets, automate login, process passenger data, solve CAPTCHA, or defeat a site control. If the page blocks the capture, stop.

Performance, reliability, and cost

For a single modestly sized public page, browser startup and page loading will usually dominate the capture step. Reusing one browser process can reduce startup overhead if you have a permitted batch of pages, but keep each capture restrained and avoid high-frequency polling. Full-page images use more storage than viewport or element images, especially on long pages.

A scheduled run is reliable only if the runner is available, the URL remains public, the browser environment is installed, and the output location persists. Log the start time, result, and output filename; alert on repeated failures without creating rapid retry loops. A local schedule has no hosting charge but depends on your computer. Hosted execution and storage may have their own costs and retention rules; check the provider’s current terms. This guide does not assume a particular scheduler or quote a price for one.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server. One GET request can return an image or PDF, so you do not need to install and schedule a browser just to request a capture. Check the API documentation for request options and use only with a page you are permitted to capture.

curl -G "https://api.screenshotneo.com/v1/shot" \
  -d access_key=YOUR_API_KEY \
  --data-urlencode url=https://www.indianrail.gov.in/ \
  -o railway-page.webp

The API call itself is not a scheduler; invoke it from an approved job runner if you need recurring captures. ScreenshotNeo accepts cookie or consent banners like a visitor and removes 60+ known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers identify 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 a month with no card; paid plans start at $5 for 3,000 screenshots.

Create a free ScreenshotNeo account for 1,000 screenshots a month with no card.

FAQ

Can I use this to capture a page that requires an IRCTC login?

This workflow is for public pages that do not require sign-in. Avoid storing credentials or authenticated page state for recurring capture, especially where account or traveller information could appear.

Does a successful screenshot mean the recurring capture is permitted?

No. Technical success does not establish permission. The published terms and privacy policy raise relevant limits, and the reviewed text does not explicitly resolve private recurring screenshots. Check current policy and ask IRCTC for permission where appropriate.

Why does the same page look different each day?

The content may have changed, or the browser environment may differ. Keep browser version, OS, viewport, and capture mode consistent, and retain timestamps to distinguish page changes from rendering variation.

Can the job keep retrying until a CAPTCHA disappears?

No. Stop when a challenge or block appears. Do not automate ticket activity or evade anti-fraud controls.