从网站(JSON)获取JSON [英] Get JSON from website (instagram)
问题描述
我最近想到了从instagram帐户及其帖子中抓取信息的想法,例如评论数或喜欢数.到目前为止,我发现在chrome中调试时发现了例如链接 https:/网络"标签下的/www.instagram.com/instagram/?__a 返回带有所需信息的JSON,但实际加载的内容仍然是正常的网站html代码.
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.
到目前为止,我在python中使用以下代码进行了尝试:
so far I tried in python with this code:
import urllib.request
r = urllib.request.urlopen(url)
print(r.read())
或在javascript中:
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);
};
所以我的问题是,当使用这些功能时,我仅获取网站代码( html ),有没有办法仅获取后台加载的JSON?我知道人们会推荐我使用instagram api,但是我没有网站或公司要注册.
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.
推荐答案
我遇到了一个问题,试图使API达到我想要的目的,实际上只需要JSON数据,包括用于特定帐户的图像的URL和标题.
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.
使用以下GET请求:
https://www.instagram.com/account_name/?__a=1
其中account_name是我要抓取的配置文件.
where account_name is the profile I'm scraping.
它返回我执行任务所需的所有JSON.
It returns all JSON I needed for my task.
这篇关于从网站(JSON)获取JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!