Skip to content

Instantly share code, notes, and snippets.

@blackbing
Created May 25, 2018 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blackbing/e72d66f34f07369b3946a0a639981385 to your computer and use it in GitHub Desktop.
Save blackbing/e72d66f34f07369b3946a0a639981385 to your computer and use it in GitHub Desktop.
get link sticker from line store
// > node index.js 'https://store.line.me/stickershop/product/11383/zh-Hant'
const puppeteer = require('puppeteer') ;
const fs = require('fs');
const http = require('https');
const process = require('process');
var url = process.argv[2];
(async () => {
const timeout = 30000;
const browser = await puppeteer.launch({args: ['--disable-dev-shm-usage', '--disable-gpu','--no-sandbox','--single-process'], headless: false, timeout});
const page = await browser.newPage();
await page.setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36');
await page.goto(url, { timeout });
const links = await page.evaluate(() => {
const els = document.querySelectorAll('.mdCMN09Image');
const links = [];
els.forEach((el) => {
const id = (/\/([\d]+)\//).exec(el.style.backgroundImage)[1];
const url = `https://stickershop.line-scdn.net/stickershop/v1/sticker/${id}/IOS/sticker_animation@2x.png;compress=true`;
links.push({ id, url });
});
return Promise.resolve(links);
});
links.forEach((link) => {
download(link.url, link.id);
})
await page.close();
await browser.close();
})();
async function download(url, name) {
var file = fs.createWriteStream(name + ".png");
var request = http.get(url, function(response) {
response.pipe(file);
});
return request;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment