基本用法
元数据与信息
获取帖子元数据和用户信息
📊 元数据与信息
instaloader 不仅能下载媒体文件,还能获取丰富的元数据。
默认保存的元数据
每个帖子默认会生成:
| 文件 | 内容 |
|---|---|
*.jpg / *.mp4 | 媒体文件 |
*.json.xz | 完整元数据(压缩的 JSON) |
*.txt | 帖子说明文字 |
控制元数据
# 不保存元数据 JSON
instaloader --no-metadata-json profile_name
# 不保存说明文字
instaloader --no-captions profile_name
# 不压缩 JSON(保存为 .json 而非 .json.xz)
instaloader --no-compress-json profile_name
# 保存地理位置信息
instaloader --geotags profile_name用 Python 获取用户信息
import instaloader
L = instaloader.Instaloader()
L.load_session_from_file("YOUR_USERNAME")
profile = instaloader.Profile.from_username(L.context, "profile_name")
print(f"用户名: {profile.username}")
print(f"全名: {profile.full_name}")
print(f"简介: {profile.biography}")
print(f"粉丝数: {profile.followers}")
print(f"关注数: {profile.followees}")
print(f"帖子数: {profile.mediacount}")
print(f"是否公开: {not profile.is_private}")
print(f"是否认证: {profile.is_verified}")获取帖子详细信息
import instaloader
L = instaloader.Instaloader()
post = instaloader.Post.from_shortcode(L.context, "CxxxxxxYYYY")
print(f"发布时间: {post.date_utc}")
print(f"点赞数: {post.likes}")
print(f"评论数: {post.comments}")
print(f"说明文字: {post.caption}")
print(f"是否视频: {post.is_video}")
print(f"类型: {post.typename}") # GraphImage, GraphVideo, GraphSidecar
print(f"标签: {post.caption_hashtags}")
print(f"提及: {post.caption_mentions}")获取评论
import instaloader
L = instaloader.Instaloader()
L.load_session_from_file("YOUR_USERNAME")
post = instaloader.Post.from_shortcode(L.context, "CxxxxxxYYYY")
for comment in post.get_comments():
print(f"@{comment.owner.username}: {comment.text}")获取关注者 / 关注列表
import instaloader
L = instaloader.Instaloader()
L.load_session_from_file("YOUR_USERNAME")
profile = instaloader.Profile.from_username(L.context, "profile_name")
# 关注者
for follower in profile.get_followers():
print(f"粉丝: @{follower.username}")
# 关注列表
for followee in profile.get_followees():
print(f"关注: @{followee.username}")获取关注者/关注列表可能触发 Instagram 的速率限制,建议添加适当延迟。