From b4142df4833e1f91699bdf9fb9f1a7e1bb7fe249 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 12 Mar 2026 12:48:18 +1100 Subject: [PATCH] umdate --- scrap_new_items.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/scrap_new_items.js b/scrap_new_items.js index d86ff19..b759636 100644 --- a/scrap_new_items.js +++ b/scrap_new_items.js @@ -15,7 +15,7 @@ async function safeGetContent(page) { } catch (err) { // Nếu navigation xảy ra → chờ page ổn định lại rồi đọc tiếp if (err.message.includes("Execution context was destroyed")) { - await page.waitForNetworkIdle({ idleTime: 1000 }).catch(() => {}); + await page.waitForNetworkIdle({ idleTime: 1000 }).catch(() => { }); return await page.content(); } throw err; @@ -117,11 +117,12 @@ async function scrapeWithPuppeteer(store) { nodes.forEach((node) => { const payload = {}; // ---------------- LINK + ID ---------------- - const linkEl = node.querySelector("div.su-media__image a"); + const linkEl = node.querySelector("div.su-image a"); // if (!linkEl) return; - - payload.link_detail = linkEl?.href || ""; - const idMatch = linkEl.href.match(/\/itm\/(\d+)/); + const linkDetail = linkEl && linkEl?.href ? linkEl?.href : "" + if (!linkDetail) return; + payload.link_detail = linkDetail; + const idMatch = linkDetail.match(/\/itm\/(\d+)/); if (!idMatch) return; payload.id = idMatch[1];