Last active
October 8, 2019 06:41
-
-
Save ng9891/53289cfbc4d2fe0011eecc8298ede66b 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 browser = await puppeteer.launch(); | |
const page = await browser.newPage(); | |
await page.goto('https://www.instagram.com/p/B3UZAnJHCOX/'); | |
await page.content() | |
const len = await page.evaluate(() => { | |
len = (document.querySelector('._6CZji .coreSpriteRightChevron')) ? document.querySelectorAll('div.tN4sQ li._-1_m6').length : 1 | |
return Promise.resolve(len); | |
}); | |
console.log(len); | |
for (i = 0; i < len; i++) { | |
let url = await page.evaluate(x => { | |
imgs = document.querySelectorAll('._97aPb img'); | |
btn = document.querySelector('._6CZji .coreSpriteRightChevron') | |
if (btn) btn.click() | |
if (x == 0) { | |
if (imgs[0].className == "_8jZFn") return Promise.resolve(imgs[0].previousSibling.getAttribute('src')); // it's a video | |
return Promise.resolve(imgs[0].getAttribute('src')); | |
} | |
if (imgs[1].className == "_8jZFn") return Promise.resolve(imgs[1].previousSibling.getAttribute('src')); | |
return Promise.resolve(imgs[1].getAttribute('src')); | |
}, i); | |
console.log(url); | |
await page.waitFor(450); //TODO: Wait for transition to end. Hardcoded. | |
} | |
await page.screenshot({ | |
path: 'screenshot.png' | |
}); | |
await browser.close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment