← back to Eur Recrawl
download-pricelist.mjs
15 lines
// download-pricelist.mjs <url> <outfile> — download a trade asset using the authed session.
import { chromium } from 'playwright';
import fs from 'node:fs';
import path from 'node:path';
const url = process.argv[2];
const out = process.argv[3] || 'data/osborne-pricelist.pdf';
fs.mkdirSync(path.dirname(out), { recursive: true });
const ctx = await chromium.launchPersistentContext(path.join(process.cwd(), '.auth', 'osbtrade'), { headless: true, channel: 'chrome' });
const resp = await ctx.request.get(url, { timeout: 60000 });
const buf = await resp.body();
console.log('status:', resp.status(), '| type:', resp.headers()['content-type'], '| bytes:', buf.length);
if (resp.ok()) { fs.writeFileSync(out, buf); console.log('saved ->', out); }
else console.log('download failed; first bytes:', buf.toString('utf8', 0, 200));
await ctx.close();