node.js - 为什么我不能在不使用 NodeJS 中的 API 的情况下获取所有 Instagram 帖子

标签 node.js instagram

请注意,截至今天 2020 年 3 月,Instagram 发生了很大变化,因此,这个问题与以前的问题不同。
问题是我总是得到 12 个帖子,而不是使用非 Instagram-API 方式的所有帖子。我遇到过很多解决方案,但现在所有解决方案都只返回 12 个帖子,即使是著名的:
https://www.instagram.com/instagram/?__a=1
这就是我得到的 Instagram 拥有 6282 个帖子的帐户:
enter image description here
我也尝试了以下技巧,但它也返回了 12 个帖子:

async function instagramPhotos () {
    // It will contain our photos' links
    const res = []
    
    try {
        const userInfoSource = await Axios.get('https://www.instagram.com/instagram/')

        // userInfoSource.data contains the HTML from Axios
        const jsonObject = userInfoSource.data.match(/<script type="text\/javascript">window\._sharedData = (.*)<\/script>/)[1].slice(0, -1)

        const userInfo = JSON.parse(jsonObject)
        // Retrieve only the first 10 results
        const mediaArray = userInfo.entry_data.ProfilePage[0].graphql.user.edge_owner_to_timeline_media.edges
        for (let media of mediaArray) {
            const node = media.node
            
            // Process only if is an image
            if ((node.__typename && node.__typename !== 'GraphImage')) {
                continue
            }

            // Push the thumbnail src in the array
            res.push(node.thumbnail_src)
        }
    } catch (e) {
        console.error('Unable to retrieve photos. Reason: ' + e.toString())
    }
    
    return res
}
有许多 npm 模块声称它们可以在不使用 Instagram API 的情况下获取提要,但最终它们只返回 12 个帖子,例如:( instagram-nodejs-without-api )
我运行以下代码,我也只得到 12 个帖子 :
let Instagram = require('instagram-nodejs-without-api');
Instagram = new Instagram()

const username="instagram"
const password="123hola" 

Instagram.getCsrfToken().then((csrf) =>
{
  Instagram.csrfToken = csrf;
}).then(() =>
{
  return Instagram.auth(username, password).then(sessionId =>
  {
    Instagram.sessionId = sessionId

    return Instagram.getUserDataByUsername(username).then((t) =>
    {
        console.log(t)
    })

  })
}).catch(console.error);
我的下一步是对 Instagram 个人资料进行网络抓取,但特别是当图像在 6000 左右时非常慢,是否有任何优雅的方法来获取这些帖子?我只想得到我的帖子,所以我不介意登录。

最佳答案

由于我需要从具体的个人资料中获取帖子,因此我在 chrome 浏览器中打开了个人资料,打开了控制台并运行以下代码以获取所有帖子:

//LOOPING ALL (credit www.hamzadiaz.com)
let posts = []
setInterval(()=>{
var inputs = document.getElementsByClassName('v1Nh3 kIKUG  _bz0w'); 
for(var i=0; i<inputs.length;i++) {
 if(!posts.includes(inputs[i].getElementsByTagName("a")[0].href)){
    posts.push(inputs[i].getElementsByTagName("a")[0].href)
  }
}
},500);

关于node.js - 为什么我不能在不使用 NodeJS 中的 API 的情况下获取所有 Instagram 帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60908590/

相关文章:

node.js - 使用中兴MF831接收短信不起作用

node.js - 使用 nodemailer 发送电子邮件在 Heroku 上失败

node.js - react 应用程序的状态与我数据库中的状态不一致?

instagram - 如何从 Instagram API 获取全分辨率图像

instagram - Instagram 用户名的字符限制

javascript - 无法使用 instafeed.js 检索 instagram 图片说明

node.js - 使用 Node.js 访问虚拟串行端口会出现错误或没有打开事件

node.js - 通过连接几个表获取不同的数据 Sequelize ORM

php - 如何在没有 API 的情况下获取 Instagram 中主题标签的所有图像?

api - Instagram oauth api 给出 {"error_message": "Matching code was not found or was already used.", "code": 400, "error_type": "OAuthException"}