Skip to content

Instantly share code, notes, and snippets.

@rage311
Created August 7, 2018 22:03
Show Gist options
  • Save rage311/cf27989f8d9eab4e9c7de4b5bb9e34cd to your computer and use it in GitHub Desktop.
Save rage311/cf27989f8d9eab4e9c7de4b5bb9e34cd to your computer and use it in GitHub Desktop.
Small Node Express app that uses puppeteer to screenshot and return the item stats DOM of a requested TAKProject item ID
const express = require('express');
const puppeteer = require('puppeteer');
const app = express();
app.get('/:id', async (req, res) => {
const itemId = req.params.id;
console.log('Request itemId: ' + itemId);
const browser = await puppeteer.launch({args:['--no-sandbox']});
const page = await browser.newPage();
await page.goto(
'https://www.takproject.net/allaclone/item.php?id=' + itemId
);
const itemElement = await page.$('div.item-wrapper');
if (!itemElement) {
await browser.close();
return res.send('error');
}
const bytes = await itemElement.screenshot();
await browser.close();
res.set('Content-Type', 'image/png');
res.set('Content-Length', bytes.length);
res.send(bytes);
});
app.get('/', (req, res) => { res.send('Hello') });
app.listen(3000, () => console.log('Listening on port 3000...'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment