【问题标题】:Get list of users who commented or liked post on instagram with Python使用 Python 获取在 instagram 上发表评论或点赞的用户列表
【发布时间】:2019-08-21 12:59:56
【问题描述】:

我在 Python 中发现了Instaloader lib,它允许抓取 Instagram 个人资料。它非常好,但我无法找到一种方法来获取在 instagram 上评论或喜欢帖子的用户列表。

我查看了所有文档,但找不到答案。这是文档:https://instaloader.github.io/as-module.html

这是我的代码:

import instaloader

L = instaloader.Instaloader() #nalazenje stvari sa instagrama

profile = instaloader.Profile.from_username(L.context, 'jlo') #daj mi pratioce od datog user-a
print(profile.get_posts())

for post in profile.get_posts():

    post_likes = post.get_likes()
    post_comments = post.get_comments()

    print(post_likes)  # post_likes object
    print(post_comments) # # post_comments object

    # post_likes.name  post_likes.username  post_likes.user    DOES NOT WORK
    # post_comments.name  post_comments.username  post_comments.user    DOES NOT WORK

【问题讨论】:

    标签: python instagram instaloader


    【解决方案1】:

    get_likes() 生成一个生成器,用于迭代喜欢帖子的帐户的个人资料。

    get_comments() 产生一个命名元组,owner 是发帖人的帐户。因此,您的代码的工作实现将如下所示:

    import instaloader
    
    L = instaloader.Instaloader() #nalazenje stvari sa instagrama
    
    profile = instaloader.Profile.from_username(L.context, 'jlo') #daj mi pratioce od datog user-a
    print(profile.get_posts())
    
    for post in profile.get_posts():
    
        post_likes = post.get_likes()
        post_comments = post.get_comments()
    
        print(post_likes)  # post_likes object
        print(post_comments) # # post_comments object
    
        # Iterate over all likes of the post. A Profile instance of each likee is yielded.
        for likee in post_likes:
            print(likee.username)
    
        # Iterate over all comments of the post.
        # Each comment is represented by a PostComment namedtuple with fields 
        # text (string), created_at (datetime), id (int), owner (Profile) 
        # and answers (~typing.Iterator[PostCommentAnswer]) if available.
        for comment in post_comments:
            print(comment.owner.username)
    
    

    【讨论】:

    • 我怎样才能得到喜欢的时间戳,我的意思是喜欢发生的确切时间?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-19
    • 2014-01-30
    • 1970-01-01
    • 2014-11-07
    • 1970-01-01
    相关资源
    最近更新 更多