Created
December 9, 2017 11:29
-
-
Save conanak99/e9312799ff04094466309031639c38e4 to your computer and use it in GitHub Desktop.
This file contains 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
const puppeteer = require('puppeteer'); | |
const download = require('image-downloader'); | |
(async() => { | |
const browser = await puppeteer.launch(); | |
console.log('Browser openned'); | |
const page = await browser.newPage(); | |
const url = 'http://kenh14.vn/ai-roi-cung-khac-cac-hot-girl-nay-cung-khong-ngoai-le-khi-vong-1-cu-ngay-cang-phong-phao-20171207193958533.chn'; | |
await page.goto(url); | |
console.log('Page loaded'); | |
const imgLinks = await page.evaluate(() => { | |
let imgElements = document.querySelectorAll('.sp-img-zoom > img, .sp-img-lightbox > img, .detail-img-lightbox > img'); | |
imgElements = [...imgElements]; | |
let imgLinks = imgElements.map(i => i.getAttribute('src')); | |
return imgLinks; | |
}); | |
console.log(imgLinks); | |
// Tải các ảnh này về thư mục hiện tại | |
await Promise.all(imgLinks.map(imgUrl => download.image({ | |
url: imgUrl, | |
dest: __dirname | |
}))); | |
await browser.close(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment