| const puppeteer = require('puppeteer-extra'); |
| const StealthPlugin = require('puppeteer-extra-plugin-stealth'); |
| const express = require('express'); |
| const path = require('path'); |
|
|
| puppeteer.use(StealthPlugin()); |
| const app = express(); |
| app.use(express.urlencoded({ extended: true })); |
| app.use(express.json()); |
|
|
| |
| app.get('/', (req, res) => { |
| res.send(` |
| <html> |
| <head> |
| <title>AQSO Scraper Engine</title> |
| <style>body{font-family:sans-serif;padding:20px;background:#1a1a1a;color:#fff}input{padding:10px;width:300px}button{padding:10px;background:#00ff00;border:none;cursor:pointer}pre{background:#000;padding:10px;overflow:auto;max-height:500px;border:1px solid #333}</style> |
| </head> |
| <body> |
| <h1>Web Scraper Engine</h1> |
| <form action="/scrape" method="POST"> |
| <input type="url" name="url" placeholder="Paste link website di sini..." required> |
| <button type="submit">SCRAPE SEKARANG</button> |
| </form> |
| </body> |
| </html> |
| `); |
| }); |
|
|
| app.post('/scrape', async (req, res) => { |
| const { url } = req.body; |
| let browser; |
| try { |
| browser = await puppeteer.launch({ |
| args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage', '--disable-gpu'], |
| executablePath: process.env.PUPPETEER_EXECUTABLE_PATH |
| }); |
| const page = await browser.newPage(); |
| |
| |
| await page.setRequestInterception(true); |
| page.on('request', (req) => { |
| if(['image', 'stylesheet', 'font', 'media'].includes(req.resourceType())) req.abort(); |
| else req.continue(); |
| }); |
|
|
| await page.goto(url, { waitUntil: 'networkidle2', timeout: 90000 }); |
|
|
| |
| const result = await page.evaluate(() => { |
| return { |
| title: document.title, |
| url: window.location.href, |
| content: document.body.innerText, |
| links: Array.from(document.querySelectorAll('a')).map(a => a.href) |
| }; |
| }); |
|
|
| res.json({ success: true, data: result }); |
| } catch (e) { |
| res.status(500).json({ error: e.message }); |
| } finally { |
| if (browser) await browser.close(); |
| } |
| }); |
|
|
| app.listen(7860, '0.0.0.0', () => console.log('Engine ready on port 7860')); |
|
|