此代码用于下载所有照片和视频。
from instaloader import Instaloader, Profile
L = Instaloader()
PROFILE = "username"
profile = Profile.from_username(L.context, PROFILE)
posts_sorted_by_likes = sorted(profile.get_posts(), key=lambda post: post.likes,reverse=True)
for post in posts_sorted_by_likes:
L.download_post(post, PROFILE)现在我只想下载视频,但我不能。我如何过滤这段代码仅用于视频?
发布于 2022-02-19 06:17:43
Post有一个is_video 属性
for post in posts_sorted_by_likes:
if post.is_video:
L.download_post(post, PROFILE)发布于 2022-03-29 15:57:14
有时候'is_video‘是不够的,所以您可以只删除那些没有.mp4扩展的:
for file in os.listdir(path):
if not file.endswith(".mp4"):
os.remove(path + file)https://stackoverflow.com/questions/71182479
复制相似问题