question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`get_posts_by_search` has no return

See original GitHub issue

Hello, guys! I’m having trouble using get_posts_by_search to get posts. Here’s my code:

import facebook_scraper as fb

fb.set_cookies("cookies.txt")
keywords = "nintendo"

for post in fb.get_posts_by_search(keywords, pages=10, options={"comments": True, "reactors": True, "allow_extra_requests": True}):
    print(post['text'])

It returns no errors but also no posts. Only a few times it can work as expected but it really confuses me. Do you know how to fix it? Very appreciated for your reply!

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8

github_iconTop GitHub Comments

4reactions
yangsu10yencommented, Sep 22, 2022

I came across same situation. I modifed source code below, then solved. I suppose that Facebook’s site codes changed. Hope it helps.

 class SearchPageParser(PageParser):
    cursor_regex = re.compile(r'href[:=]"[^"]+(/search/[^"]+)"')
    cursor_regex_2 = re.compile(r'href":"[^"]+(/search/[^"]+)"')

    def get_page(self) -> Page:                                         // add
          return super()._get_page('div[data-module-role="TOP_PUBLIC_POSTS"]', 'article')    // add
           
    def get_next_page(self) -> Optional[URL]:
        if self.cursor_blob is not None:
            match = self.cursor_regex.search(self.cursor_blob)
            if match:
                return match.groups()[0]
            match = self.cursor_regex_2.search(self.cursor_blob)
            if match:
                value = match.groups()[0]
                return value.encode('utf-8').decode('unicode_escape').replace('\\/', '/')
2reactions
KKHYAcommented, Nov 27, 2022

@yangsu10yen It works! Sorry for replying too late. But here’s another problem. get_posts_by_search ends after getting 9 posts. Do you know why it happens?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Forcing WP_Query To Return No Results - Cameron Jones
Forcing WP_Query To Return No Results ... The WP_Query object is the primary way of retrieving a post, or a number of posts...
Read more >
Empty search input does not return all posts
I am working on WordPress custom post type search functionality. When I have searched with an empty value, it does not return all...
Read more >
Is it possible to have get_posts() or WP_Query not return the ...
The only way I'm aware is to rewrite the SQL query with a filter from a plugin (or functions.php in your theme).
Read more >
get_posts() | Function - WordPress Developer Resources
Retrieves an array of the latest posts, or posts matching the given criteria.
Read more >
relevanssi_do_query() | Relevanssi
No return value, the results are placed in the posts attribute of the WP_Query object. Usage. This function can be used to run...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found