Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_posts() with limit #2269

Open
BobikRekordik opened this issue May 20, 2024 · 2 comments
Open

get_posts() with limit #2269

BobikRekordik opened this issue May 20, 2024 · 2 comments
Labels
feature suggestion Feature suggestion

Comments

@BobikRekordik
Copy link

BobikRekordik commented May 20, 2024

Hi. Make the get_posts() method accept the limit on the received data as an argument. There are pages with more than 100 thousand posts and it took me about an hour to do this.
I would like to get only the last n posts instead of all the posts by sending an argument.
posts = user.get_posts(50); #latest 50 posts only :)

@Mesheo
Copy link

Mesheo commented May 20, 2024

Hey @BobikRekordik! I saw your issue when running into the same problem. I went a little bit inside the code and I believe it does not make sense to change the behave of get_post() function, since is more a NodeGenerator at the end of our scrapping process.
Also, it already has this functionality of limiting posts download inside the self.posts_download_loop() method, for some reason the external calling functions were just not adjusted to receive and pass this argument further

I made a PR with the changes that worked here, you just need to use the new recommend function to get profile posts: instaloader.download_profiles()

Here it is a snippet code of how get some limiting amount of posts after this change

from instaloader import Instaloader, Profile

USERNAME = "cachorroquentealex"
Instaloader = Instaloader()
profile = Profile.from_username(Instaloader.context, USERNAME)
Instaloader.download_profiles(profiles=[profile], max_count=2) # it will download only 2 posts

@BobikRekordik
Copy link
Author

BobikRekordik commented May 23, 2024

Hey @BobikRekordik! I saw your issue when running into the same problem. I went a little bit inside the code and I believe it does not make sense to change the behave of get_post() function, since is more a NodeGenerator at the end of our scrapping process. Also, it already has this functionality of limiting posts download inside the self.posts_download_loop() method, for some reason the external calling functions were just not adjusted to receive and pass this argument further

I made a PR with the changes that worked here, you just need to use the new recommend function to get profile posts: instaloader.download_profiles()

Here it is a snippet code of how get some limiting amount of posts after this change

from instaloader import Instaloader, Profile

USERNAME = "cachorroquentealex"
Instaloader = Instaloader()
profile = Profile.from_username(Instaloader.context, USERNAME)
Instaloader.download_profiles(profiles=[profile], max_count=2) # it will download only 2 posts

Thanks, it's a good option, but the method downloads the whole page, I need it to return a List[] from these posts, there is a shortcode, id, description and others...

example:

posts = method(profile, count=5)
for post in posts:
   print(post.shortcode)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature suggestion Feature suggestion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants