Files
tenderpilot/etendersni-detail.mjs

63 lines
2.0 KiB
JavaScript
Raw Normal View History

import axios from 'axios';
import * as cheerio from 'cheerio';
const client = axios.create({
timeout: 8000,
maxRedirects: 5,
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
}
});
(async () => {
try {
// First, get the list page and extract entryIds
console.log('Fetching home page to find tenders...');
const listResp = await client.get('https://etendersni.gov.uk/epps/home.do?status=open');
const $ = cheerio.load(listResp.data);
// Extract entryIds from links
const entryIds = new Set();
const links = [];
$('a[href*="entryId"]').each((i, el) => {
const href = $(el).attr('href');
const text = $(el).text().trim();
const match = href.match(/entryId=(\d+)/);
if (match) {
entryIds.add(match[1]);
links.push({ id: match[1], text: text.substring(0, 60), href });
}
});
console.log(`Found ${entryIds.size} tenders`);
console.log('\nFirst 3 tenders:');
links.slice(0, 3).forEach(l => {
console.log(` ID: ${l.id}, Text: "${l.text}"`);
});
// Now try to view a detail page
if (links.length > 0) {
const firstId = links[0].id;
const detailUrl = `https://etendersni.gov.uk/epps/viewInfo.do?sec=newItems&entryId=${firstId}`;
console.log(`\nFetching detail page for ID ${firstId}...`);
const detailResp = await client.get(detailUrl);
const d$ = cheerio.load(detailResp.data);
console.log('Detail page structure:');
console.log('Title:', d$('h1, h2, .title, [class*="title"]').first().text().trim().substring(0, 100));
// Look for tender details
d$('.card, .panel, [class*="detail"], [class*="info"]').each((i, el) => {
const content = d$(el).text().trim();
if (content.length > 0 && content.length < 300) {
console.log(` ${content.substring(0, 80)}`);
}
});
}
} catch (e) {
console.log('Error:', e.message);
}
})();