Michael Kariv
Michael Kariv

Reputation: 1453

using instaloader to only download the instagram post caption

Is it possible to only download the caption (the description) of a post, given the post short code, using python 3.12 and the latest version of the instaloader library? I am insterested in using instaloder as a library module, not the cli utility.

If not, can you suggest another similar python library that would allow me do so?

Im I correct in thinking that instagram API does not allow doing so for a non-user posts?

Update: the solution is in the accepted answer. The full code is below

import instaloader
L = instaloader.Instaloader()
post = instaloader.Post.from_shortcode(L.context, SHORTCODE)
print(post.caption)

Upvotes: 0

Views: 276

Answers (1)

Alen S Thomas
Alen S Thomas

Reputation: 1133

As per the documentation of Instaloader, you do have access to downloading the caption of the post: https://instaloader.github.io/module/structures.html#instaloader.Post.caption

And you can probably load the library first and create an instaloader instance and then run a sample code snippet as follows:

# Loading a post using its shortcode
post = instaloader.Post.from_shortcode(L.context, 'ShortCode')

# Print the caption of the post
print(post.caption)

Upvotes: 1

Related Questions