moda20 / facebook-scraper

Scrape Facebook public pages without an API key
MIT License
60 stars 23 forks source link

How do I get the mbasicHeaders.json? #51

Closed Surayuth closed 2 months ago

Surayuth commented 2 months ago

Sorry, I'm new here. I can select the device in the developer tools. I just don't know what to do next from that step.

zazer0 commented 2 months ago

I followed these instructions in a previous issue and it worked! https://github.com/moda20/facebook-scraper/issues/22#issuecomment-1869612291

zazer0 commented 2 months ago

To clarify, once you've got the Python snippet from curlconverter.com (as described in #22):

Copy+paste the "cookies" dict into a file cookies.json; change all the single quotes to double, will look smth like this:

{
    "sb": "YOUR_VALUES_HERE",
    "datr": "YOUR_VALUES_HERE",
    "ps_n": "YOUR_VALUES_HERE",
    "ps_l": "YOUR_VALUES_HERE",
    "c_user": "YOUR_VALUES_HERE",
    "presence": "YOUR_VALUES_HERE",
    "wd": "YOUR_VALUES_HERE",
    "dpr": "YOUR_VALUES_HERE",
    "locale": "YOUR_VALUES_HERE",
    "wl_cbv": "YOUR_VALUES_HERE",
    "xs": "YOUR_VALUES_HERE",
    "fr": "YOUR_VALUES_HERE",
    "vpd": "YOUR_VALUES_HERE",
    "m_page_voice": "YOUR_VALUES_HERE"
}

Then, you tweak the example snippet to pass in cookies= and it'll work! Example below:

from facebook_scraper import get_posts, _scraper
import json

### Original example snippet
# with open('./mbasicHeaders.json', 'r') as file:
#    _scraper.mbasic_headers = json.load(file)

### Using cookies instead of the mBasicHeaders!
cookies = None
with open('./cookies.json', 'r') as file:
    cookies = json.load(file)

for post in get_posts('NintendoAmerica', pages=1, 
                      base_url="https://mbasic.facebook.com",
                      start_url="https://mbasic.facebook.com/NintendoAmerica?v=timeline",
                      cookies=cookies): # added this line
    print(post['text'][:50])
moda20 commented 2 months ago

@Surayuth i am closing this issue since the instructions from @zazer0 do suffice, reopen this or another issue if you still need answers