Install Playwright
npm init -y
npm install playwright
npx playwright install
Extract only PDF links
grep -oP 'https://samagam.kvs.gov.in/mis/hpc[^"]+' urls.txt
Read URLs from a text file (BEST for many links)
Create a file:
urls.txt
Script
const { chromium } = require('playwright');
const fs = require('fs');
(async () => {
const urls = fs.readFileSync('urls.txt','utf8')
.split('\n')
.filter(Boolean);
const browser = await chromium.launch();
const page = await browser.newPage();
let i = 1;
for (const url of urls) {
console.log("Saving:", url);
await page.goto(url, { waitUntil: 'networkidle' });
await page.emulateMedia({ media: 'screen' });
await page.pdf({
path: `${i}.pdf`,
format: 'A4',
printBackground: true
});
i++;
}
await browser.close();
})();
Example Output
1.pdf
2.pdf
3.pdf
4.pdf