0

如何添加配置文件列表?现在我必须一一写出来。我知道可以使用 profile_list = ['profile1','profile2','profile3', ...] 但我不知道如何在代码中实现它。

``from instaloader import Instaloader, Profile
import instaloader
from instaloader.structures import Post 

list_of_profile = [''] 
for list_element in list_of_profile: 
    L = Instaloader() 
    profile = Profile.from_username(L.context, list_element)
    posts_sorted_by_likes = sorted(profile.get_posts(), key=lambda post: post.likes, reverse=True) 

quant = 3
for elements in range(quant):
     L.download_post(posts_sorted_by_likes[elements], list_element)
4

1 回答 1

0

我们不能为您做很多事情,因为您还没有描述您将如何处理此列表。你让我们猜。您的问题只是谈论使用配置文件列表,但您的代码正在处理帖子。你没有说你想要什么,你不应该让我们猜测。您想要列表中个人资料中点赞数排名前三的帖子吗?这可以做到,但你应该告诉我们这就是你想要的。显然,如果您想要每个配置文件的前三名,则需要在循环中提取前三名。否则,您将获得整体前三名。

from instaloader import Instaloader, Profile
from instaloader.structures import Post 

list_of_profile = [''] 
L = Instaloader() 
posts = []
quant = 3

for name in list_of_profile: 
    profile = Profile.from_username(L.context, name)
    # Get all the posts, sorted by descending likes.
    posts_sorted_by_likes = sorted(posts, key=lambda post: post.likes, reverse=True)[:quant]
    # Add the top three to our master list.
    posts.extend( posts_sorted_by_likes )

# Fetch the master list.
for post in posts:
     L.download_post(post, list_element)
于 2021-08-15T04:46:37.427 回答