从Post Instagram Python获取喜欢

时间:2019-03-21 20:07:36

标签: python web-scraping instagram instagram-api

我想从instagram帖子中抓取数据。我可以获得照片链接,喜欢计数和评论计数,但无法获得喜欢别人的帖子和评论的人的用户名。我使用pyInstaParser。有什么办法吗?

1 个答案:

答案 0 :(得分:0)

我之前做了这个,但这应该可以满足您的尝试(使用https代理来防止Instagram限制请求)


import requests, sys, time
from random import choice
if len(sys.argv) < 2:sys.exit(f"Usage: {sys.argv[0]} <Post Link> <Proxy List>")


Comments = 0
ProxList = []
Prox = open(sys.argv[2], "r")readlines()
for line in ReadProx:
    ProxList.append(line.strip('\n'))

while True:
    try:
        g = requests.get(sys.argv[1], proxies={'https://': 'https://'+choice(ProxList)})
        print(g.json())
        time.sleep(5)
        if len(g.json()['data']['shortcode_media']['edge_liked_by']['count']) > Comments:
            print(f"[+] Like | {g.json()['data']['shortcode_media']['edge_liked_by']['edges'][int(Comments)]['node']['username']}")
            if len(g.json()['data']['shortcode_media']['edge_liked_by']['count']) == Comments - 1:
                pass
            else:
                Comments += 1
        time.sleep(1.5)     
    except KeyboardInterrupt: sys.exit("Done")
    except Exception as e: print(e)