Created
January 16, 2019 21:35
-
-
Save amycheng/701e7e34957d33c87a9fd7a4d873f821 to your computer and use it in GitHub Desktop.
Get instagram images by tag
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 fs = require('fs'), | |
puppeteer = require('puppeteer'), | |
tag = 'sushi'; | |
(async () => { | |
const browser = await puppeteer.launch(); | |
const page = await browser.newPage(); | |
let sharedData, images; | |
await page.goto(`https://www.instagram.com/explore/tags/${tag}`); | |
sharedData = await page.evaluate(() => { | |
return window._sharedData; | |
}); | |
images = sharedData.entry_data.TagPage[0].graphql.hashtag.edge_hashtag_to_media.edges; | |
fs.writeFile("data.json", JSON.stringify({data:images}), function(err) { | |
if(err) { | |
return console.log(err); | |
} | |
console.log("The file was saved!"); | |
process.exit(); | |
}); | |
})(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment