const axios = require("axios"); const cheerio = require("cheerio"); async function nhentai(query) { try { const searchUrl = `https://nhentai.net/search/?q=${encodeURIComponent(query)}`; const { data } = await axios.get(searchUrl, { headers: { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36" }, }); const $ = cheerio.load(data); const results = []; $("div.gallery").each((_, el) => { const href = $(el).find("a").attr("href"); const title = $(el).find("div.caption").text().trim(); if (href && title) { const id = href.match(/\/g\/(\d+)\//)?.[1] || null; results.push({ id, title, link: `https://nhentai.net${href}`, }); } }); return results; } catch (err) { console.error("[NHENTAI SCRAPE ERROR]", err.message); return []; } } module.exports = { nhentai };