facebook-scraper
facebook-scraper copied to clipboard
It is imposible to scrap some pages! (get_posts)
Hello, right now I want to scrape some pharmacy but the function "get_posts" throw me "[]". Can you explain me what happend?
The page is "www.facebook.com/brasil.farmacias" or "www.facebook.com/Farmaciascefafa"
Thnx!!
The brasil.farmacias is a private group on fb so you probably need to include your login credentials while trying to scrape any data from it; whereas for the Farmaciascefafa... I am able to scrape (see the example below) but remember to include your cookies.txt
from facebook_scraper import get_posts
import pandas as pd
# Initialize dataframe to scrape Facebook post
post_df_full = pd.DataFrame(columns = [])
# Start to collect Facebook post data by facebook_scraper library
for post in get_posts('Farmaciascefafa', cookies='cookies.txt', extra_info=True, pages=5, options={"comments": True}):
post_entry = post
fb_post_df = pd.DataFrame.from_dict(post_entry, orient='index')
fb_post_df = fb_post_df.transpose()
post_df_full = post_df_full.append(fb_post_df)
# Save dataframe into JSON
post_df_full.to_json(r'fb_scrapped_farmacias.json', indent = 4, orient='records')
@richylyq Thanks for the help, I appreciate a lot. But can you explain me a lit of bit more about? That file "cookies.txt" I have to create a note and paste it in the folder where do I have the file of Python? Or what? Sorry for the problems
@richylyq Thanks for the help, I appreciate a lot. But can you explain me a lit of bit more about? That file "cookies.txt" I have to create a note and paste it in the folder where do I have the file of Python? Or what? Sorry for the problems
hey @LChito sorry I just saw your reply.. 🙈
The README.MD
actually has the instructions, I followed through to get the cookies.txt; for convenience sake, I'll just copy it here
The path to a file containing cookies in Netscape or JSON format. You can extract cookies from your browser after logging into Facebook with an extension like Get Cookies.txt (Chrome) or Cookie Quick Manager (Firefox). Make sure that you include both the c_user cookie and the xs cookie, you will get an InvalidCookies exception if you don't.
you just have to head over to your Facebook page and export the cookies information using the extension you just installed; and copy it into the cookies.txt
then just follow the code example i shared earlier and you should be good to go.
Hello! @richylyq sorry to bother you, but this continue to happen :(
by using above code i am getting error, even i give the cookie adress by following above instrustions ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))