Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
79
rated 0 times [  80] [ 1]  / answers: 1 / hits: 26548  / 6 Years ago, wed, february 7, 2018, 12:00:00

I recently got the idea to scrape information from instagram accounts and their posts, like the amount of comments or amount of likes. I got so far that I figured out while debugging in chrome that for example the link https://www.instagram.com/instagram/?__a under the network tab returns a JSON with the wanted information, but what is actually loaded is still the normal website html code.



json



so far I tried in python with this code:



import urllib.request
r = urllib.request.urlopen(url)
print(r.read())


or in javascript :



window.onload = function () {
res = fetch(https://www.instagram.com/instagram/?__a, {
method: 'get'
}).then(function (data) {
return data.json();
}).catch(function (error) {
console.log(ERROR.concat(error.toString()));
});
console.log(res.user);
};


So the problem I have, is that when using these functions I only get the website code (html), is there a way to only get the JSON which is loaded in the background? I know people will recommend me using the instagram api, but I have no website nor a company to register.


More From » python

 Answers
34

I ran into a problem trying to get the API to do what I wanted, and really just needed JSON data including urls and captions for images for a specific account.



Use the following GET request:



https://www.instagram.com/account_name/?__a=1



where account_name is the profile I'm scraping.



It returns all JSON I needed for my task.


[#55225] Monday, February 5, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mireyag

Total Points: 73
Total Questions: 107
Total Answers: 85

Location: Ukraine
Member since Sun, Dec 13, 2020
4 Years ago
;