Scraping the picture of an instagram account with highest likes

吃可爱长大的小学妹 提交于 2020-01-02 21:11:31

问题


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.


回答1:


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)


来源:https://stackoverflow.com/questions/53056466/scraping-the-picture-of-an-instagram-account-with-highest-likes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!