← back to Eur Recrawl
probe-osbtrade.mjs
59 lines
// probe-osbtrade.mjs [SKU] — reuse the authed Osborne trade session to discover how
// trade PRICE is exposed: map the nav (STOCK ENQUIRY / PRICE LISTS), open STOCK ENQUIRY,
// search a test SKU, and dump price-looking output + any bulk price-list download links.
import { chromium } from 'playwright';
import path from 'node:path';
const sku = process.argv[2] || 'W7216-01';
const ctx = await chromium.launchPersistentContext(path.join(process.cwd(), '.auth', 'osbtrade'), {
headless: false, channel: 'chrome', viewport: { width: 1440, height: 900 },
});
const page = ctx.pages()[0] || await ctx.newPage();
await page.goto('https://tradenew.osborneandlittle.com/user/dashboard', { waitUntil: 'domcontentloaded', timeout: 60000 }).catch((e) => console.log('nav', e.message));
await page.waitForTimeout(3000);
// map the main nav links
const nav = await page.evaluate(() =>
[...document.querySelectorAll('a[href]')]
.filter((a) => /stock|price|enquiry|report|product|search|catalog/i.test((a.innerText || '') + ' ' + a.href))
.map((a) => `${(a.innerText || '').trim().slice(0, 22)} -> ${a.getAttribute('href')}`).slice(0, 20));
console.log('nav links:\n ' + [...new Set(nav)].join('\n '));
// try STOCK ENQUIRY
const stockLink = await page.$('a:has-text("STOCK ENQUIRY"), a:has-text("Stock Enquiry")');
if (stockLink) {
await stockLink.click().catch(() => {}); await page.waitForTimeout(3500);
console.log(`\n[STOCK ENQUIRY] @ ${page.url()}`);
const fields = await page.evaluate(() => [...document.querySelectorAll('input,select,button')].map((e) => ({ tag: e.tagName, type: e.type || '', name: e.name || '', id: e.id || '', ph: e.placeholder || '', txt: (e.innerText || e.value || '').slice(0, 18) })).filter((e) => e.type !== 'hidden').slice(0, 20));
console.log(' fields:', JSON.stringify(fields));
// search the test SKU
const box = await page.$('input[type=text]:not([name*=user i]), input[name*=search i], input[id*=search i], input[name*=sku i], input[name*=pattern i]');
if (box) {
await box.fill(sku).catch(() => {});
const go = await page.$('button:has-text("Search"), button:has-text("Enquiry"), button[type=submit], input[type=submit]');
if (go) await go.click().catch(() => {}); else await page.keyboard.press('Enter').catch(() => {});
await page.waitForTimeout(4000);
const res = await page.evaluate((s) => {
const t = document.body ? document.body.innerText : '';
const prices = [...t.matchAll(/(?:£|\$|€)\s?\d[\d.,]*/g)].map((m) => m[0]).slice(0, 20);
const nums = [...t.matchAll(/\b\d{1,4}\.\d{2}\b/g)].map((m) => m[0]).slice(0, 20);
const near = t.split('\n').filter((l) => new RegExp(s.split(/[-\/]/)[0], 'i').test(l)).slice(0, 6);
return { url: location.href, prices, nums, near };
}, sku);
console.log(` search "${sku}" @ ${res.url}`);
console.log(' £/$ prices:', res.prices.join(' | ') || '(none)');
console.log(' money nums:', res.nums.join(' | ') || '(none)');
console.log(' lines w/ code:', JSON.stringify(res.near));
} else console.log(' no search box found on stock enquiry');
await page.screenshot({ path: 'probe-osbtrade-stock.png' }).catch(() => {});
}
// note the PRICE LISTS section (possible bulk download)
const plLink = await page.$('a:has-text("PRICE LISTS"), a:has-text("Price Lists")');
if (plLink) {
const href = await plLink.getAttribute('href').catch(() => null);
console.log(`\n[PRICE LISTS] href: ${href}`);
}
await page.waitForTimeout(1500);
await ctx.close();