// ผลประกาศจัดซื้อจัดจ้าง // ประกาศจัดซื้อจัดจ้าง const { execSync } = require("child_process"); const cheerio = require("cheerio"); const fs = require("fs"); const path = require("path"); const BASE = "https://ladsawai.go.th"; // const OUT = path.join(process.cwd(), "ผลประกาศจัดซื้อจัดจ้าง"); const OUT = path.join(process.cwd(), "ประกาศจัดซื้อจัดจ้าง"); fs.mkdirSync(OUT, { recursive: true }); function curlHtml(url) { return execSync( `curl -L -s "${url}" -H "User-Agent: Mozilla/5.0" -H "Accept-Language: th-TH,th;q=0.9"`, { encoding: "utf8", maxBuffer: 20 * 1024 * 1024 } ); } function absUrl(src) { if (!src) return null; if (src.startsWith("http")) return src; if (src.startsWith("/")) return BASE + src; return BASE + "/" + src; // กัน "public/..." } function scrapeOnePage(menuId, page, saveHtml = false) { const url = `${BASE}/public/list/data/index/menu/${menuId}/page/${page}`; const html = curlHtml(url); if (saveHtml) { fs.writeFileSync(path.join(OUT, `page-menu-${menuId}-page-${page}.html`), html, "utf8"); } const $ = cheerio.load(html); const items = []; $(".row.data-row").each((_, row) => { const el = $(row); const left = el.find(".col-12.col-sm-10").first(); const a = left.find("a.listdataconfig_link").first(); // title อยู่ใน