understanding get_posts() parameters pages and post_per_page?
See original GitHub issueI don’t know if I’m misunderstanding facebook-scraper, my own code, or I’m seeing a bug. When I ran the code fragment:
for username in usernames:
total_posts = 12
if username == frequent_poster:
total_posts = 24
posts_per_page = 4
pages = (total_posts + posts_per_page - 1) // posts_per_page
print('')
print('total_posts = %d, posts_per_page = %d, pages = %d' % (total_posts, posts_per_page, pages))
posts = get_posts(username, cookies=cookie_file, pages=pages, extra_info=True,
options={'posts_per_page': posts_per_page, 'allow_extra_requests': False, 'HQ_images': False})
print('Actual number of posts = %d' % (sum(1 for i in posts)))
I got the output:
total_posts = 12, posts_per_page = 4, pages = 3
Actual number of posts = 9
total_posts = 12, posts_per_page = 4, pages = 3
Actual number of posts = 9
total_posts = 12, posts_per_page = 4, pages = 3
Actual number of posts = 30
...
total_posts = 12, posts_per_page = 4, pages = 3
Actual number of posts = 30
total_posts = 24, posts_per_page = 4, pages = 6
Actual number of posts = 63
total_posts = 12, posts_per_page = 4, pages = 3
Actual number of posts = 30
total_posts = 12, posts_per_page = 4, pages = 3
Actual number of posts = 9
total_posts = 12, posts_per_page = 4, pages = 3
Actual number of posts = 30
...
total_posts = 12, posts_per_page = 4, pages = 3
Actual number of posts = 30
total_posts = 12, posts_per_page = 4, pages = 3
Actual number of posts = 9
total_posts = 12, posts_per_page = 4, pages = 3
Actual number of posts = 30
...
total_posts = 12, posts_per_page = 4, pages = 3
Actual number of posts = 30
total_posts = 12, posts_per_page = 4, pages = 3
Actual number of posts = 6
total_posts = 12, posts_per_page = 4, pages = 3
Actual number of posts = 31
total_posts = 12, posts_per_page = 4, pages = 3
Actual number of posts = 30
I’m trying to understand how post extraction and its parameters work, and I expected the actual number of posts to be less than or equal to total_posts
in each case. My goal is to make as few requests as possible.
What am I misunderstanding?
As always, I appreciate your help.
Issue Analytics
- State:
- Created 2 years ago
- Comments:32
Top Results From Across the Web
What Is the WordPress get_posts Function & How Do You Use ...
The WordPress get_posts function is a method for retrieving a custom set of posts based on specified criteria. It's important to note that...
Read more >WordPress get_posts: How to Use This PHP Function to Build ...
WordPress get_posts is a powerful function allowing developers to retrieve pieces of content from the WordPress database.
Read more >get_posts() | Function - WordPress Developer Resources
Retrieves an array of the latest posts, or posts matching the given criteria. ... set of parameters within a page, then get_posts is...
Read more >How to Use the WordPress get_posts Function
The WordPress get_posts function allows developers to retrieve post data from the WordPress database by taking the ID of a given post and ......
Read more >How to limit get_posts()? - WordPress Stack Exchange
UPDATE #1: I want to use, say, 5 posts per page and use multiple queries on the same page using get_posts() (not query_posts...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hmm, after commenting out
I get 100 and everything seems to work. 😊
Thanks.
The warning is safe to ignore