【问题标题】:How can access all of the images in Instagram slides (posts with multiple images or videos) with Instaloader?如何使用 Instaloader 访问 Instagram 幻灯片中的所有图像(包含多个图像或视频的帖子)?
【发布时间】:2021-01-09 19:43:40
【问题描述】:

我正在使用 Instaloader 开发 Instagram 抓取机器人。这是我的代码的一部分,它通过每个配置文件从安装中获取图像 url:

def scrapImageAddresses(PROFILE):
    print(PROFILE)
    L = Instaloader()
    L.login('####', "####")
    profile = Profile.from_username(L.context, PROFILE)
    imageList = []
    for post in profile.get_posts():
        imageList.append({
            'url': post.url,
            'media_id': post.mediaid
        })
    return imageList

但对于像this 这样的幻灯片,它只获取帖子的第一个图片。我想要帖子中的所有图片。 我该怎么做?

【问题讨论】:

    标签: python instagram instaloader


    【解决方案1】:

    您可以遍历每篇文章中的所有 Sidecar 节点(幻灯片)并将相应的 url 添加到列表中:

    def scrapImageAddresses(PROFILE):
        print(PROFILE)
        L = Instaloader()
        L.login('####', "####")
        profile = Profile.from_username(L.context, PROFILE)
        imageList = []
        for post in profile.get_posts():
            for slide in post.get_sidecar_nodes():
                imageList.append({
                    'url': slide.video_url if slide.is_video else slide.display_url,
                    'media_id': post.mediaid
                })
        return imageList
    

    文档:Instagram Structures — Instaloader documentation

    【讨论】:

      猜你喜欢
      • 2012-02-27
      • 2016-03-27
      • 1970-01-01
      • 2018-05-28
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      相关资源
      最近更新 更多