fix: KöPi - nur König Pilsener anzeigen, Flaschengröße ergänzt
This commit is contained in:
@@ -123,14 +123,25 @@ async function scrapeOffersWithPuppeteer() {
|
||||
const grid = document.querySelector('[data-testid="OfferGrid"]');
|
||||
const gridOffers = grid ? Array.from(grid.querySelectorAll('[role="listitem"]')).map(item => {
|
||||
const img = item.querySelector('img');
|
||||
const ps = item.querySelectorAll('p');
|
||||
const brand = ps[0]?.textContent?.trim() || null;
|
||||
const name = ps[1]?.textContent?.trim() || null;
|
||||
const store = ps[2]?.textContent?.trim() || null;
|
||||
const price = item.querySelector('.text-primary, [class*="text-primary"]')?.textContent?.trim() || null;
|
||||
const baseUnit = ps[3]?.textContent?.trim() || null;
|
||||
return { type:'offer', brand, name, store, price, baseUnit, image: img?.src || null };
|
||||
}).filter(o => o.name) : [];
|
||||
const ps = Array.from(item.querySelectorAll('p')).map(p => p.textContent.trim());
|
||||
const brand = ps[0] || null;
|
||||
const name = ps[1] || null;
|
||||
const store = ps[2] || null;
|
||||
const price = item.querySelector('[class*="text-primary"]')?.textContent?.trim() || null;
|
||||
const baseUnit = ps[5] || ps[4] || null; // z.B. "(1 L = 1,20)"
|
||||
const imgTitle = img?.title || '';
|
||||
const imgAlt = img?.alt || '';
|
||||
// Flaschengröße aus imgTitle/imgAlt extrahieren
|
||||
const sizeMatch = (imgTitle + ' ' + imgAlt).match(/(\d+[\.,]\d*\s*[lLxX×]\s*\d*\s*(?:Fl\.?|Flasche|Flaschen|Dose|Dosen|Pack|Kiste)?|\d+\s*(?:×|x)\s*\d+[\.,]\d*\s*[lL]|\d+\s*[lL]|\d+\s*ml)/i);
|
||||
const size = sizeMatch?.[0]?.trim() || null;
|
||||
return { type:'offer', brand, name, store, price, baseUnit, size, image: img?.src || null, imgTitle };
|
||||
}).filter(o => {
|
||||
if (!o.name) return false;
|
||||
// Nur König Pilsener — kein König Ludwig, König der Löwen etc.
|
||||
const fullText = (o.imgTitle + ' ' + (o.brand||'') + ' ' + (o.name||'')).toLowerCase();
|
||||
return fullText.includes('pilsener') || fullText.includes('pilsen') ||
|
||||
(fullText.includes('könig') && !fullText.includes('ludwig') && !fullText.includes('löwen') && !fullText.includes('weiss'));
|
||||
}) : [];
|
||||
|
||||
return { brochureOffers, gridOffers };
|
||||
});
|
||||
|
||||
@@ -128,8 +128,9 @@ function GridOfferCard({ offer }) {
|
||||
{offer.price}
|
||||
</div>
|
||||
)}
|
||||
{offer.baseUnit && (
|
||||
<div style={{ color:'rgba(255,255,255,0.3)', fontFamily:'monospace', fontSize:9 }}>
|
||||
{(offer.size || offer.baseUnit) && (
|
||||
<div style={{ color:'rgba(255,255,255,0.35)', fontFamily:'monospace', fontSize:10, marginTop:2 }}>
|
||||
{offer.size && <span>{offer.size} · </span>}
|
||||
{offer.baseUnit}
|
||||
</div>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user