gpt4 book ai didi

python - 从 Instagram 帖子获取点赞 python

转载 作者:太空宇宙 更新时间:2023-11-03 21:07:46 25 4
gpt4 key购买 nike

我想从 Instagram 帖子中抓取数据。我可以获取照片链接、点赞数和评论数,但无法获取喜欢帖子和评论的用户的用户名。我使用 pyInstaParser。有什么办法可以做到这一点吗?

最佳答案

我不久前做了这个,但这应该适合你想要做的事情(使用 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)

关于python - 从 Instagram 帖子获取点赞 python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55288514/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com