【问题标题】:How to get instagram profile photos with javascript?如何使用 javascript 获取 Instagram 个人资料照片?
【发布时间】:2021-06-25 11:34:39
【问题描述】:

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

如何从这里获取个人资料图片?最好有纯javascript,但经过几次尝试后它不起作用。也许是因为 CORS

我试试这个,但它给用户找不到错误。

function getPhoto(a) {
  
  // validation for instagram usernames
  let regex = new RegExp(/^(?!.*\.\.)(?!.*\.$)[^\W][\w.]{0,29}$/);
  let validation = regex.test(a);

  if(validation) {
  
    $.get("https://www.instagram.com/"+a+"/?__a=1")
    .done(function(data) { 

      // getting the url
      let photoURL = data["graphql"]["user"]["profile_pic_url_hd"];

      // update img element
      $("#photoReturn").attr("src",photoURL)
     
     })
    .fail(function() { 
      // code for 404 error 
      alert('Username was not found!')
    })
  
  } else {
  
    alert('The username is invalid!')
  }

}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<img src="" id="photoReturn">

<br><br>

<input type="text" id="usernameInput">

<button onclick="getPhoto($('#usernameInput').val().trim())">Get profile photo</button>

【问题讨论】:

    标签: javascript jquery api web instagram


    【解决方案1】:

    您现在需要使用服务器端代码来执行此操作.. 看看 https://www.youtube.com/watch?v=fHvjJ6IHQmw(使用 PHP 驱动的 https://github.com/restyler/instagram-php-scraper

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-24
      • 1970-01-01
      • 2015-08-13
      • 1970-01-01
      • 1970-01-01
      • 2013-09-28
      • 1970-01-01
      相关资源
      最近更新 更多