Feat/parapharmacy api #38

Merged
Ichitux merged 25 commits from feat/parapharmacy-api into main 2026-07-16 15:38:59 +00:00
Showing only changes of commit fa74a6e060 - Show all commits
+8 -3
View File
@@ -107,10 +107,13 @@ async function scrapeSource(browser, source, query) {
}); });
console.log(` 🔍 Product info:`, JSON.stringify(productInfo, null, 2)); console.log(` 🔍 Product info:`, JSON.stringify(productInfo, null, 2));
const products = await page.evaluate((selectors) => { const products = await page.evaluate((selectors, searchQuery) => {
const results = []; const results = [];
const cards = document.querySelectorAll(selectors.product); const cards = document.querySelectorAll(selectors.product);
// Get the search query to filter relevant products
const query = searchQuery.toLowerCase();
cards.forEach(card => { cards.forEach(card => {
// Try data attributes first (Promofarma style) // Try data attributes first (Promofarma style)
let name = card.getAttribute('data-name'); let name = card.getAttribute('data-name');
@@ -132,7 +135,9 @@ async function scrapeSource(browser, source, query) {
if (name && priceStr) { if (name && priceStr) {
const price = parseFloat(priceStr.replace(/[^0-9.,]/g, '').replace(',', '.')) || 0; const price = parseFloat(priceStr.replace(/[^0-9.,]/g, '').replace(',', '.')) || 0;
if (name && price > 0 && price < 1000) { // Filter: only include products that contain the search query
const nameLower = name.toLowerCase();
if (name && price > 0 && price < 1000 && nameLower.includes(query)) {
results.push({ results.push({
name: name.substring(0, 200), name: name.substring(0, 200),
price, price,
@@ -144,7 +149,7 @@ async function scrapeSource(browser, source, query) {
}); });
return results; return results;
}, config.selectors); }, config.selectors, query);
console.log(` 📦 Found ${products.length} products`); console.log(` 📦 Found ${products.length} products`);
return products.slice(0, 10).map(p => ({ return products.slice(0, 10).map(p => ({