有没有办法以编程方式解析instagram?__ a = 1页?

时间:2018-11-27 02:14:26

标签: python json instagram

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

当我们在instagram帐户链接的末尾添加?__a=1时,我们会得到一个json页面,其中包含许多用户信息,例如:

{"logging_page_id":"profilePage_11288110","show_suggested_profiles":false,"graphql":{"user":{"biography":"\ud83d\udc47 \u2018Bangers & Ballads OUT NOW\u2019\ud83d\udc47","blocked_by_viewer":false,"country_block":false,"external_url":"https://bangers.lnk.to/bangersballadsIn","external_url_linkshimmed":"https://l.instagram.com/?u=https%3A%2F%2Fbangers.lnk.to%2FbangersballadsIn&e=ATMgu1_Mj-1mm4EEU1h6pkhKhcRYlXypnC3RezuzzA9l8ftEs832t_Gc3vk3VCI5GXPNRR84EcLgjog2","edge_followed_by":{"count":494093},"followed_by_viewer":false,"edge_follow":{"count":1536},"follows_viewer":false,"full_name":"example","has_channel":false,"has_blocked_viewer":false,"highlight_reel_count":14,"has_requested_viewer":false,"id":"11288110","is_business_account":true,"is_joined_recently":false,"business_category_name":"Creators & Celebrities","business_email":"gleaveeliot@gmail.com","business_phone_number":"","business_address_json":"{\"street_address\": \"\", \"zip_code\": \"\", \"city_name\": \"\", \"region_name\": \"\", \"countcode\": \"\"}","is_private":false,"is_verified":true,"edge_mutual_followed_by":{"count":0,"edges":...

我想知道我是否可以使用程序来解析"id":"11288110"

我只是尝试使用

for username in fashion_influencers:
        response = requests.get("https://www.instagram.com/example/?__a=1")
        print(response.text)

看看我是否可以访问数据,但是当我使用请求将其打印出来时,什么都没有显示出来。

这不一定是明智的选择,但我只需要给定用户名,就可以删除instagram用户的ID。

2 个答案:

答案 0 :(得分:0)

您需要登录才能看到对https://www.instagram.com/example/?__a=1的回复

仅请求https://www.instagram.com/example并在响应文本中搜索ID

import requests

url = "https://www.instagram.com/example"

r  = requests.get(url)

data = r.text
query_str = 'logging_page_id":"profilePage_'
start = data.find(query_str)  + len(query_str)
print(data[start:start + 8])

答案 1 :(得分:0)

尝试

<div class="instagram-feed" id="insta-feed"></div>

$(document).ready(function() {
  var list ='';     
  $.ajax({
    url:"https://www.instagram.com/<instagram id>/?__a=1",
    success: function (response) {
       var result =response.graphql.user.edge_owner_to_timeline_media.edges; 
       $.each(result, function(key, val) {
        list += ''+
        '<a target="_blank" href="https://www.instagram.com/p/'+val.node.shortcode+'"><img src="'+val.node.thumbnail_src+'" width=250></a>'+
        '';
         });
        $('#insta-feed').append(list);                      
    }
  });
});