BOl*_*o84 2 web-scraping instagram
我正在尝试编写一个从 Instagram 帐户获取数据的脚本,特别是下载点赞数最高的帐户的图片。这是可能的吗?我怎么能用一些现有的图书馆做这样的事情?我不是数据抓取方面的专家,这个项目的一部分是让我学习如何去做。
Instaloader是一个 Python 库,只需几行代码就可以轻松实现:
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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1212 次 |
| 最近记录: |