More changes than expected. Mobile version improvements & PWA
Build & Push Docker Images / test-backend (push) Successful in 44s
Build & Push Docker Images / test-frontend (push) Successful in 52s
Build & Push Docker Images / build-backend (push) Failing after 34s
Build & Push Docker Images / build-frontend (push) Failing after 30s
Build & Push Docker Images / test-backend (push) Successful in 44s
Build & Push Docker Images / test-frontend (push) Successful in 52s
Build & Push Docker Images / build-backend (push) Failing after 34s
Build & Push Docker Images / build-frontend (push) Failing after 30s
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
const puppeteer = require('puppeteer-extra');
|
||||
|
||||
async function scrapeOpenFoodFacts(query, browser) {
|
||||
const page = await browser.newPage();
|
||||
const url = `https://world.openfoodfacts.org/cgi/search.pl?search_terms=${encodeURIComponent(query)}&search_simple=1&action=process`;
|
||||
|
||||
try {
|
||||
await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||||
|
||||
const products = await page.evaluate(() => {
|
||||
const results = [];
|
||||
const items = document.querySelectorAll('#search_results li');
|
||||
|
||||
items.forEach(item => {
|
||||
const linkEl = item.querySelector('a');
|
||||
const titleEl = item.querySelector('span:not([class])') || item.querySelector('.list_product_name'); // heuristic
|
||||
|
||||
let link = linkEl ? linkEl.href : null;
|
||||
if (link && !link.startsWith('http')) {
|
||||
link = `https://world.openfoodfacts.org${link}`;
|
||||
}
|
||||
|
||||
if (linkEl && linkEl.title) {
|
||||
results.push({
|
||||
name: linkEl.title.trim(),
|
||||
price: 'N/A', // OFF usually doesn't have prices
|
||||
link: link,
|
||||
source: 'OpenFoodFacts'
|
||||
});
|
||||
}
|
||||
});
|
||||
return results.slice(0, 5);
|
||||
});
|
||||
|
||||
return products;
|
||||
} catch (error) {
|
||||
console.error(`[OpenFoodFacts] Error scraping ${query}:`, error.message);
|
||||
return [];
|
||||
} finally {
|
||||
await page.close();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = scrapeOpenFoodFacts;
|
||||
Reference in New Issue
Block a user