进阶用法
速率限制与应对
处理 Instagram 的速率限制和封禁
⏱️ 速率限制与应对
Instagram 速率限制
Instagram 对 API 请求有严格的速率限制。当达到限制时,instaloader 会自动等待。
常见限制场景
| 操作 | 大约限制 | 冷却时间 |
|---|---|---|
| 浏览帖子 | ~200 请求/小时 | 5-10 分钟 |
| 获取关注者 | ~100 请求/小时 | 10-30 分钟 |
| 下载 Stories | 变动较大 | 5-15 分钟 |
instaloader 的自动处理
429 Too Many Requests - Rate limited
Waiting for 5 minutes before retrying...instaloader 会自动检测 429 错误并等待后重试。
手动添加延迟
# 每次请求间隔 2 秒
instaloader --login YOUR_USERNAME \
--request-timeout 300 profile_namePython API 方式:
import instaloader
import time
L = instaloader.Instaloader(
max_connection_attempts=3,
request_timeout=300.0,
)
L.load_session_from_file("YOUR_USERNAME")
profile = instaloader.Profile.from_username(L.context, "profile_name")
for post in profile.get_posts():
L.download_post(post, target=profile.username)
time.sleep(2) # 每个帖子间隔 2 秒避免被封的建议
- 不要太贪心:每次运行限制下载数量
- 使用
--fast-update:避免重复请求已下载的内容 - 添加间隔:在请求之间加上延迟
- 避免并行:不要同时运行多个 instaloader 实例
- 使用正常账号:新账号更容易被限制
# 保守的下载策略
import instaloader
import time
from itertools import islice
L = instaloader.Instaloader()
L.load_session_from_file("YOUR_USERNAME")
profile = instaloader.Profile.from_username(L.context, "profile_name")
# 每次最多 50 个,每个间隔 3 秒
for post in islice(profile.get_posts(), 50):
L.download_post(post, target=profile.username)
time.sleep(3)临时封禁处理
如果遇到临时封禁:
- 停止所有请求,等待至少 1 小时
- 检查账号:在浏览器中登录确认账号正常
- 减少频率:恢复后降低请求频率
- 更换 IP:如果使用代理,尝试更换节点
Instagram 会根据账号年龄、活跃度等因素动态调整限制。新账号的限制通常更严格。