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

I can't get the full commnets, only 30~ #490

Closed
blutics opened this issue Sep 24, 2021 · 15 comments
Closed

I can't get the full commnets, only 30~ #490

blutics opened this issue Sep 24, 2021 · 15 comments

Comments

@blutics
Copy link

blutics commented Sep 24, 2021

`posts = facebook_scraper.get_posts(
post_urls=[url],
options={
"comments": True,
"progress": True,
},
cookies = cookies,
extra_info=True
)

post = next(posts)
print(post)
for n, cmt in enumerate(post['comments_full']):
print(n, cmt)
print(len(post['comments_full']))`

with this code, I'm only available to see 30 of comments.

and I got an warning message about locale, which is about en_US is best but I'm in ko_KR
Am I missing something??

@neon-ninja
Copy link
Collaborator

Set your Facebook language to English, then re-export your cookies. Also, what post id are you having this problem with? Is it a video post?

@blutics
Copy link
Author

blutics commented Sep 25, 2021

the id is 4392606570798592 and it is not a video : )

@blutics
Copy link
Author

blutics commented Sep 26, 2021

setting the facebook language to english worked for me!!
Thank you for your answer!!

@blutics blutics closed this as completed Sep 26, 2021
@HakzA
Copy link

HakzA commented Sep 27, 2021

Hello,

I'm experiencing the exact same problem. I can only extract 30 comments from the post 10157405244133520 with my code:

post = next(get_posts(post_urls = [url],  # or  post_urls = [url], same results
                          options =    {'locale': 'en_US',
                                        "comments": True,
                                        "allow_extra_requests": True,
                                        "reactors": True,
                                        "progress": True,
                                        "extra_info": True
                                         }))

I have tried changing the language by adding the following:

facebook_scraper._scraper.session.cookies.update({'locale': 'en_US'})

but I'm still only getting 30 comments. Any help would be much appreciated, and thank you for this repo.

@neon-ninja
Copy link
Collaborator

Setting that cookie does nothing, you need to set your language on the Facebook end

@HakzA
Copy link

HakzA commented Sep 27, 2021

@neon-ninja I changed my facebook language and extracted the cookie.json using EditThisCookie, but I'm still only getting 30 comments, while the post has 400+ comments (not just replies). The 'locale' is set to 'en_US', any suggestions?

@neon-ninja
Copy link
Collaborator

This is working fine for me, the code:

post = next(get_posts(post_urls=[10157405244133520], cookies="cookies.json", options={"comments":True, "progress": True}))
print(post["comments"], len(post["comments_full"]), sum(len(c["replies"]) for c in post["comments_full"]))

outputs:

301 158 142

@HakzA
Copy link

HakzA commented Sep 28, 2021

If I run your code above, I get the error:

File "/opt/project/test.py", line 46, in test
     print(post["comments"], len(post["comments_full"]), sum(len(c["replies"]) for c in post["comments_full"]))
File "/opt/project/test.py", line 46, in <genexpr>
     print(post["comments"], len(post["comments_full"]), sum(len(c["replies"]) for c in post["comments_full"]))
KeyError: 'replies

If I try to upgrade to latest master:

pip install --user --upgrade git+https://github.com/kevinzg/facebook-scraper.git

Then I get the error:

ERROR: Command errored out with exit status 1:
     command: /opt/conda/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-rz7nvlhr/demjson_49ecc8ba06834ed3aa9456dbe9b22bd4/setup.py'"'"'; __file__='"'"'/tmp/pip-install-rz7nvlhr/demjson_4
9ecc8ba06834ed3aa9456dbe9b22bd4/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"'
, '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-g71g4lrv
         cwd: /tmp/pip-install-rz7nvlhr/demjson_49ecc8ba06834ed3aa9456dbe9b22bd4/
    Complete output (1 lines):
    error in demjson setup command: use_2to3 is invalid.
    ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/96/67/6db789e2533158963d4af689f961b644ddd9200615b8ce92d6cad695c65a/demjson-2.2.4.tar.gz#sha256=31de2038a0fdd9c4c11f8bf3b13fe77bc2a128307f965c8d5fb4dc6d6f6beb79 (from https:
//pypi.org/simple/demjson/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Could not find a version that satisfies the requirement demjson<3.0.0,>=2.2.4 (from facebook-scraper) (from versions: 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.0.1, 2.2, 2.2.1, 2.2.2, 2.2.3, 2.2.4)
ERROR: No matching distribution found for demjson<3.0.0,>=2.2.4

@HakzA
Copy link

HakzA commented Sep 28, 2021

I'm running a Docker container. I'm able to install the package with:

pip install facebook-scraper

But not with:

pip install git+https://github.com/kevinzg/facebook-scraper.git

Seems like the problem is with my end, I'll have to do some more debugging.

SOLUTION:

Turns out demjson is no longer possible to install on python3 when setuptools >58.0.0 is used.. So I installed setuptools as 57.5.0, then I installed demjson==2.2.4, and then I was able to install the latest version of facebook-scraper with:

pip3 install git+https://github.com/kevinzg/facebook-scraper.git

I'm now able to get all comments.

@neon-ninja
Copy link
Collaborator

Thanks for the link. This commit (509a7ba) upgrades from demjson to demjson3

@natanlaurett
Copy link

I'm getting this same problem for comments in a video post. My Facebook's language is english and I am with the latest version of master branch. The get_posts call is:

get_posts(post_urls=post_ids, cookies="cookies.json", options={"comments":True, "progress": True, "allow_extra_requests": True})

and post_ids=["211857482296579_1798983683583943","211857482296579_1798816063600705"]

Any ideas on what am I doing wrong here, or there is a problem up with comments in video posts?

@neon-ninja
Copy link
Collaborator

Try 1d87116

@natanlaurett
Copy link

It works! Amazing, thanks!

@sinanajluan
Copy link

Traceback (most recent call last):
File "C:\Users\Lenovo T440p\PycharmProjects\facebook-scraper\ProveLuani.py", line 19, in
post = next(get_posts(post_urls=[10157405244133520], cookies="cookies.json", options={"comments":True, "progress": True}))
File "C:\Users\Lenovo T440p\PycharmProjects\facebook-scraper\facebook_scraper_init_.py", line 196, in get_posts
set_cookies(cookies)
File "C:\Users\Lenovo T440p\PycharmProjects\facebook-scraper\facebook_scraper_init_.py", line 40, in set_cookies
cookies = parse_cookie_file(cookies)
File "C:\Users\Lenovo T440p\PycharmProjects\facebook-scraper\facebook_scraper\utils.py", line 221, in parse_cookie_file
with open(filename, mode='rt') as file:
FileNotFoundError: [Errno 2] No such file or directory: 'cookies.json'

Process finished with exit code 1

@neon-ninja
Copy link
Collaborator

neon-ninja commented Aug 31, 2022

Make sure you have a cookies.json file in your working directory, extracted from your browser as per the readme

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

No branches or pull requests

5 participants