kevinzg / facebook-scraper

Scrape Facebook public pages without an API key
MIT License
2.43k stars 631 forks source link

getting data from private groups #259

Closed mpizosdim closed 3 years ago

mpizosdim commented 3 years ago

Using:

next(get_posts(group='395304918032818', pages=2, options={"allow_extra_requests": False, "comments": False, "reactors": False, "posts_per_page": 20},cookies='cookies.json'))

where '395304918032818' is a private group and cookies.json format:

[{
    "Host raw": "https://.facebook.com/",
    "Name raw": "datrasdad",
    "Path raw": "/",
    "Content raw": "fdfsfdghgjfhdf",
    "Expires": "15-05-2023 15:41:27",
    "Expires raw": "1684154487",
    "Send for": "Encrypted connections only",
    "Send for raw": "true",
    "HTTP only raw": "true",
    "SameSite raw": "no_restriction",
    "This domain only": "Valid for subdomains",
    "This domain only raw": "false",
    "Store raw": "firefox-default",
    "First Party Domain": ""
}]

gives: {StopIteration}

Also tried with credentials:

next(get_posts(group='395304918032818', pages=2, options={"allow_extra_requests": False, "comments": False, "reactors": False, "posts_per_page": 20},credentials=('username@protonmail.com', 'password')))

with same result.

Any insights?

neon-ninja commented 3 years ago

Likely a cookies issue, related to https://github.com/kevinzg/facebook-scraper/issues/262

neon-ninja commented 3 years ago

Your cookies.json doesn't look right - there should be ~7 cookies there, not just one. When extracting the cookies from Firefox, make sure you select the whole facebook.com domain and not just the one datr cookie. "Copy domain to clipboard", not "Copy cookie to clipboard"

neon-ninja commented 3 years ago

This commit (https://github.com/kevinzg/facebook-scraper/commit/f5f359ddaed473fa589b7efc595c9b490d08fd58) should make it so the scraper throws an exception if cookies are passed but some are missing