Cleanup modified & misisng files
This commit is contained in:
+36
-53
@@ -1,7 +1,3 @@
|
||||
// OpenTelemetry SDK — must be required first to instrument http, dns, etc.
|
||||
require('./tracing');
|
||||
|
||||
const { trace } = require('@opentelemetry/api');
|
||||
const puppeteer = require('puppeteer-extra');
|
||||
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
|
||||
const fs = require('fs');
|
||||
@@ -20,56 +16,43 @@ const QUERIES = [
|
||||
];
|
||||
|
||||
async function run() {
|
||||
const tracer = trace.getTracer('farmaclic-scraper');
|
||||
return tracer.startActiveSpan('scraper.run', { attributes: { 'scraper.queries': QUERIES.length } }, async (span) => {
|
||||
try {
|
||||
console.log('🚀 Starting Parapharmacy Scraper...');
|
||||
const browser = await puppeteer.launch({
|
||||
headless: 'new',
|
||||
args: ['--no-sandbox', '--disable-setuid-sandbox']
|
||||
});
|
||||
|
||||
const allResults = {};
|
||||
|
||||
for (const query of QUERIES) {
|
||||
const querySpan = tracer.startSpan('scraper.query', { attributes: { 'scraper.query': query } });
|
||||
console.log(`\n🔍 Searching for: "${query}"`);
|
||||
|
||||
const promofarmaResults = await scrapePromofarma(query, browser);
|
||||
console.log(` ✅ Promofarma: found ${promofarmaResults.length} items`);
|
||||
|
||||
const amazonResults = await scrapeAmazon(query, browser);
|
||||
console.log(` ✅ Amazon: found ${amazonResults.length} items`);
|
||||
|
||||
const googleShoppingResults = await scrapeGoogleShopping(query, browser);
|
||||
console.log(` ✅ Google Shopping: found ${googleShoppingResults.length} items`);
|
||||
|
||||
const ofFactsResults = await scrapeOpenFoodFacts(query, browser);
|
||||
console.log(` ✅ OpenFoodFacts: found ${ofFactsResults.length} items`);
|
||||
|
||||
allResults[query] = {
|
||||
promofarma: promofarmaResults,
|
||||
amazon: amazonResults,
|
||||
googleshopping: googleShoppingResults,
|
||||
openfoodfacts: ofFactsResults
|
||||
};
|
||||
querySpan.setAttribute('scraper.results.total', promofarmaResults.length + amazonResults.length + googleShoppingResults.length + ofFactsResults.length);
|
||||
querySpan.end();
|
||||
}
|
||||
|
||||
await browser.close();
|
||||
|
||||
fs.writeFileSync('results.json', JSON.stringify(allResults, null, 2));
|
||||
console.log('\n💾 Scraping finished. Results saved to results.json');
|
||||
span.setStatus({ code: 1 }); // OK
|
||||
} catch (err) {
|
||||
span.recordException(err);
|
||||
span.setStatus({ code: 2, message: err.message }); // ERROR
|
||||
throw err;
|
||||
} finally {
|
||||
span.end();
|
||||
}
|
||||
console.log('🚀 Starting Parapharmacy Scraper...');
|
||||
// Launching browser
|
||||
const browser = await puppeteer.launch({
|
||||
headless: 'new',
|
||||
args: ['--no-sandbox', '--disable-setuid-sandbox']
|
||||
});
|
||||
|
||||
const allResults = {};
|
||||
|
||||
for (const query of QUERIES) {
|
||||
console.log(`\n🔍 Searching for: "${query}"`);
|
||||
|
||||
// We run sequentially to be gentle on CPU and anti-bot systems
|
||||
const promofarmaResults = await scrapePromofarma(query, browser);
|
||||
console.log(` ✅ Promofarma: found ${promofarmaResults.length} items`);
|
||||
|
||||
const amazonResults = await scrapeAmazon(query, browser);
|
||||
console.log(` ✅ Amazon: found ${amazonResults.length} items`);
|
||||
|
||||
const googleShoppingResults = await scrapeGoogleShopping(query, browser);
|
||||
console.log(` ✅ Google Shopping: found ${googleShoppingResults.length} items`);
|
||||
|
||||
const ofFactsResults = await scrapeOpenFoodFacts(query, browser);
|
||||
console.log(` ✅ OpenFoodFacts: found ${ofFactsResults.length} items`);
|
||||
|
||||
allResults[query] = {
|
||||
promofarma: promofarmaResults,
|
||||
amazon: amazonResults,
|
||||
googleshopping: googleShoppingResults,
|
||||
openfoodfacts: ofFactsResults
|
||||
};
|
||||
}
|
||||
|
||||
await browser.close();
|
||||
|
||||
fs.writeFileSync('results.json', JSON.stringify(allResults, null, 2));
|
||||
console.log('\n💾 Scraping finished. Results saved to results.json');
|
||||
}
|
||||
|
||||
run().catch(err => {
|
||||
|
||||
Generated
+3
-2417
File diff suppressed because it is too large
Load Diff
@@ -11,12 +11,6 @@
|
||||
"license": "ISC",
|
||||
"type": "commonjs",
|
||||
"dependencies": {
|
||||
"@opentelemetry/api": "^1.9.0",
|
||||
"@opentelemetry/auto-instrumentations-node": "^0.52.0",
|
||||
"@opentelemetry/exporter-trace-otlp-grpc": "^0.55.0",
|
||||
"@opentelemetry/resources": "^1.28.0",
|
||||
"@opentelemetry/sdk-node": "^0.55.0",
|
||||
"@opentelemetry/semantic-conventions": "^1.28.0",
|
||||
"puppeteer": "^24.40.0",
|
||||
"puppeteer-extra": "^3.3.6",
|
||||
"puppeteer-extra-plugin-stealth": "^2.11.2"
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
// OpenTelemetry Node SDK bootstrap for the FarmaClic scraper.
|
||||
// Started as a side-effect require from index.js (CommonJS).
|
||||
//
|
||||
// Env vars:
|
||||
// OTEL_SERVICE_NAME — default: farmaclic-scraper
|
||||
// OTEL_EXPORTER_OTLP_ENDPOINT — OTLP gRPC endpoint (e.g. http://alloy:4317)
|
||||
|
||||
const { NodeSDK } = require('@opentelemetry/sdk-node');
|
||||
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');
|
||||
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-grpc');
|
||||
const { resourceFromAttributes } = require('@opentelemetry/resources');
|
||||
const {
|
||||
ATTR_SERVICE_NAME,
|
||||
ATTR_SERVICE_NAMESPACE,
|
||||
} = require('@opentelemetry/semantic-conventions');
|
||||
|
||||
const serviceName = process.env.OTEL_SERVICE_NAME || 'farmaclic-scraper';
|
||||
const otlpEndpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT || 'http://localhost:4317';
|
||||
|
||||
const sdk = new NodeSDK({
|
||||
resource: resourceFromAttributes({
|
||||
[ATTR_SERVICE_NAME]: serviceName,
|
||||
[ATTR_SERVICE_NAMESPACE]: 'farmaclic',
|
||||
}),
|
||||
traceExporter: new OTLPTraceExporter({ url: otlpEndpoint }),
|
||||
instrumentations: [
|
||||
getNodeAutoInstrumentations({
|
||||
'@opentelemetry/instrumentation-fs': { enabled: false },
|
||||
'@opentelemetry/instrumentation-dns': { enabled: false },
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
sdk.start();
|
||||
|
||||
const shutdown = async () => {
|
||||
try {
|
||||
await sdk.shutdown();
|
||||
} catch (err) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('OpenTelemetry shutdown failed', err);
|
||||
}
|
||||
};
|
||||
|
||||
process.on('SIGTERM', shutdown);
|
||||
process.on('SIGINT', shutdown);
|
||||
Reference in New Issue
Block a user