-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-scraper-simple.js
More file actions
69 lines (56 loc) · 2.22 KB
/
Copy pathtest-scraper-simple.js
File metadata and controls
69 lines (56 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Simple test for a few sources only
const https = require('https');
const http = require('http');
// Test a couple of simple sources
const testSources = [
{ label: 'DPW', url: 'http://www.publicworks.gov.za/tenders.html' },
{ label: 'DIRCO', url: 'https://dirco.gov.za/tenders/' }
];
async function fetchUrl(url, timeout = 8000) {
return new Promise((resolve, reject) => {
const client = url.startsWith('https') ? https : http;
const req = client.get(url, { timeout }, (res) => {
let data = '';
res.on('data', chunk => data += chunk);
res.on('end', () => resolve({ status: res.statusCode, data }));
});
req.on('error', reject);
req.on('timeout', () => {
req.destroy();
reject(new Error('Request timeout'));
});
});
}
async function testScraper() {
console.log('🧪 Testing tender scraper connectivity...\n');
for (const source of testSources) {
console.log(`📡 Testing ${source.label}: ${source.url}`);
try {
const startTime = Date.now();
const result = await fetchUrl(source.url);
const endTime = Date.now();
console.log(` ✅ Status: ${result.status}`);
console.log(` 📏 Size: ${result.data.length} bytes`);
console.log(` ⏱️ Time: ${endTime - startTime}ms`);
// Check for tender-related content
const tenderKeywords = ['tender', 'bid', 'rfq', 'rfp', 'procurement', 'quotation'];
const hasTenderContent = tenderKeywords.some(keyword =>
result.data.toLowerCase().includes(keyword)
);
console.log(` 🔍 Tender content: ${hasTenderContent ? 'YES' : 'NO'}`);
if (hasTenderContent) {
// Look for reference numbers
const refPattern = /\b[A-Z]{2,10}[\s\/\-]\d{2,6}[\s\/\-]\d{4}\b/g;
const refs = result.data.match(refPattern) || [];
console.log(` 📋 Found ${refs.length} reference numbers`);
if (refs.length > 0) {
console.log(` 📝 Sample refs: ${refs.slice(0, 3).join(', ')}`);
}
}
} catch (error) {
console.log(` ❌ Error: ${error.message}`);
}
console.log('');
}
}
testScraper();