Reputation: 133
I am trying to write a script that gets data from an instagram account, particularly, downloads the picture of the account with highest number of likes. Is this possible to do? How can I do such a thing with some existing libraries? I'm not an expert in data scraping and part of this project is for me to learn how to do it.
Upvotes: 2
Views: 2046
Reputation: 637
There is Instaloader, a Python library, with which it is easy to do that with just a few lines:
from instaloader import Instaloader, Profile
PROFILE = "..." # Insert profile name here
L = Instaloader()
# Obtain profile
profile = Profile.from_username(L.context, PROFILE)
# Get all posts and sort them by their number of likes
posts_sorted_by_likes = sorted(profile.get_posts(), key=lambda post: post.likes, reverse=True)
# Download the post with the most likes
L.download_post(posts_sorted_by_likes[0], PROFILE)
Upvotes: 6