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,54 @@
|
||||
const puppeteer = require('puppeteer-extra');
|
||||
|
||||
async function scrapeGoogleShopping(query, browser) {
|
||||
const page = await browser.newPage();
|
||||
const url = `https://www.google.com/search?q=${encodeURIComponent(query)}&tbm=shop`;
|
||||
|
||||
try {
|
||||
await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||||
|
||||
const products = await page.evaluate(() => {
|
||||
const results = [];
|
||||
// Google Shopping results are often inside blocks with class .sh-dgr__grid-result or similar
|
||||
const cards = document.querySelectorAll('.sh-dgr__grid-result, .sh-np__click-target');
|
||||
|
||||
cards.forEach(card => {
|
||||
const titleEl = card.querySelector('h3, [role="heading"]');
|
||||
const priceEl = card.querySelector('.a80p0, [data-price], span[aria-hidden="true"]:not(:empty)');
|
||||
// Fallback for price: look for any element mimicking a price format
|
||||
let priceText = null;
|
||||
if (priceEl) {
|
||||
priceText = priceEl.innerText.trim();
|
||||
} else {
|
||||
const spans = card.querySelectorAll('span');
|
||||
spans.forEach(span => {
|
||||
if (span.innerText.includes('€') || span.innerText.match(/\d+,\d{2}/)) {
|
||||
priceText = span.innerText.trim();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const linkEl = card.tagName === 'A' ? card : card.querySelector('a');
|
||||
|
||||
if (titleEl && priceText) {
|
||||
results.push({
|
||||
name: titleEl.innerText.trim(),
|
||||
price: priceText,
|
||||
link: linkEl ? linkEl.href : null,
|
||||
source: 'Google Shopping'
|
||||
});
|
||||
}
|
||||
});
|
||||
return results.slice(0, 5);
|
||||
});
|
||||
|
||||
return products;
|
||||
} catch (error) {
|
||||
console.error(`[Google Shopping] Error scraping ${query}:`, error.message);
|
||||
return [];
|
||||
} finally {
|
||||
await page.close();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = scrapeGoogleShopping;
|
||||
Reference in New Issue
Block a user