Created
October 31, 2017 16:03
-
-
Save fabsrc/c4e370a8dc2fa57f2e07815d7197d769 to your computer and use it in GitHub Desktop.
Get Instagram URLs by hashtag
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
function getURLsByHashtag(hashtag) { | |
let count = 0 | |
let urls = [] | |
return (function makeRequest(maxId = '') { | |
return fetch(`https://www.instagram.com/explore/tags/${hashtag}/?__a=1&max_id=${maxId}`) | |
.then(res => res.json()) | |
.then(res => { | |
console.log(++count) | |
if (res.tag.media.count > 0) { | |
urls = urls.concat(res.tag.media.nodes.map(n => 'https://www.instagram.com/p/' + n.code)) | |
} | |
if (res.tag.media.page_info.has_next_page) { | |
const maxId = res.tag.media.page_info.end_cursor | |
return makeRequest(maxId) | |
} else { | |
return urls | |
} | |
}) | |
})() | |
} | |
getURLsByHashtag('enterhashtag') | |
.then(urls => document.body.innerHTML = urls.join('<br>')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment