本文介绍了以最高的喜欢率刮取instagram帐户的图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个脚本,该脚本从instagram帐户获取数据,尤其是要下载点赞次数最多的帐户图片.这可能吗?我该如何使用某些现有的库来做这样的事情?我不是数据抓取方面的专家,这个项目的一部分对我来说是学习如何做的.

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.

推荐答案

Instaloader ,Python库,只需几行就可以轻松实现:

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)

这篇关于以最高的喜欢率刮取instagram帐户的图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 10:45