0

How could I add a list of profiles? Right now I have to write them one by one. I know that it's possible using profile_list = ['profile1','profile2','profile3', ...]but I don't know how to implement it in the code.

``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)
olamundo97
  • 25
  • 4

1 Answers1

0

We can't do very much for you because you haven't described what you're going to do with this list. You're making us guess. Your question just talks about using a list of profiles, but your code is doing something with posts. You haven't said what you want, and you shouldn't make us guess. Do you want the top three post by likes from the profiles in your list? That can be done, but you should TELL US that's what you want. And clearly, if you want the top three for each profile, you need to extract the top three within the loop. Otherwise, you'll get the top three overall.

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)
Tim Roberts
  • 48,973
  • 4
  • 21
  • 30
  • I am so sorry for no make clear what I want with my code. What I want is download the most liked photo from multiiples profiles at the same time and print the number of likes of each photo downloaded. Can you help me please? – olamundo97 Aug 15 '21 at 11:59
  • And did you look at my code? That's what I'm doing. Fetch the top three posts from each profile into the list, then download them one by one. – Tim Roberts Aug 15 '21 at 22:47