Created
May 25, 2018 10:13
-
-
Save blackbing/e72d66f34f07369b3946a0a639981385 to your computer and use it in GitHub Desktop.
get link sticker from line store
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// > 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/[email protected];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