How to scrape facebook comments using python
Show
Scrape Facebook public pages without an API key. Inspired by twitter-scraper. InstallTo install the latest release from PyPI: pip install facebook-scraper Or, to install the latest master branch: pip install git+https://github.com/kevinzg/facebook-scraper.git UsageSend the unique page name, profile name, or ID as the first parameter and you're good to go: >>> from facebook_scraper import get_posts >>> for post in get_posts('nintendo', pages=1): ... print(post['text'][:50]) ... The final step on the road to the Super Smash Bros We’re headed to PAX East 3/28-3/31 with new games Optional parameters(For the
CLI usage$ facebook-scraper --filename nintendo_page_posts.csv --pages 10 nintendo
Run Note: If you get a Post example{'available': True, 'comments': 459, 'comments_full': None, 'factcheck': None, 'fetched_time': datetime.datetime(2021, 4, 20, 13, 39, 53, 651417), 'image': 'https://scontent.fhlz2-1.fna.fbcdn.net/v/t1.6435-9/fr/cp0/e15/q65/58745049_2257182057699568_1761478225390731264_n.jpg?_nc_cat=111&ccb=1-3&_nc_sid=8024bb&_nc_ohc=ygH2fPmfQpAAX92ABYY&_nc_ht=scontent.fhlz2-1.fna&tp=14&oh=7a8a7b4904deb55ec696ae255fff97dd&oe=60A36717', 'images': ['https://scontent.fhlz2-1.fna.fbcdn.net/v/t1.6435-9/fr/cp0/e15/q65/58745049_2257182057699568_1761478225390731264_n.jpg?_nc_cat=111&ccb=1-3&_nc_sid=8024bb&_nc_ohc=ygH2fPmfQpAAX92ABYY&_nc_ht=scontent.fhlz2-1.fna&tp=14&oh=7a8a7b4904deb55ec696ae255fff97dd&oe=60A36717'], 'is_live': False, 'likes': 3509, 'link': 'https://www.nintendo.com/amiibo/line-up/', 'post_id': '2257188721032235', 'post_text': 'Don’t let this diminutive version of the Hero of Time fool you, ' 'Young Link is just as heroic as his fully grown version! Young ' 'Link joins the Super Smash Bros. series of amiibo figures!\n' '\n' 'https://www.nintendo.com/amiibo/line-up/', 'post_url': 'https://facebook.com/story.php?story_fbid=2257188721032235&id=119240841493711', 'reactions': {'haha': 22, 'like': 2657, 'love': 706, 'sorry': 1, 'wow': 123}, # if `extra_info` was set 'reactors': None, 'shared_post_id': None, 'shared_post_url': None, 'shared_text': '', 'shared_time': None, 'shared_user_id': None, 'shared_username': None, 'shares': 441, 'text': 'Don’t let this diminutive version of the Hero of Time fool you, ' 'Young Link is just as heroic as his fully grown version! Young Link ' 'joins the Super Smash Bros. series of amiibo figures!\n' '\n' 'https://www.nintendo.com/amiibo/line-up/', 'time': datetime.datetime(2019, 4, 30, 5, 0, 1), 'user_id': '119240841493711', 'username': 'Nintendo', 'video': None, 'video_id': None, 'video_thumbnail': None, 'w3_fb_url': 'https://www.facebook.com/Nintendo/posts/2257188721032235'} Notes
ProfilesThe from facebook_scraper import get_profile get_profile("zuck") # Or get_profile("zuck", cookies="cookies.txt") Outputs: {'About': "I'm trying to make the world a more open place.", 'Education': 'Harvard University\n' 'Computer Science and Psychology\n' '30 August 2002 - 30 April 2004\n' 'Phillips Exeter Academy\n' 'Classics\n' 'School year 2002\n' 'Ardsley High School\n' 'High School\n' 'September 1998 - June 2000', 'Favourite Quotes': '"Fortune favors the bold."\n' '- Virgil, Aeneid X.284\n' '\n' '"All children are artists. The problem is how to remain ' 'an artist once you grow up."\n' '- Pablo Picasso\n' '\n' '"Make things as simple as possible but no simpler."\n' '- Albert Einstein', 'Name': 'Mark Zuckerberg', 'Places lived': [{'link': '/profile.php?id=104022926303756&refid=17', 'text': 'Palo Alto, California', 'type': 'Current town/city'}, {'link': '/profile.php?id=105506396148790&refid=17', 'text': 'Dobbs Ferry, New York', 'type': 'Home town'}], 'Work': 'Chan Zuckerberg Initiative\n' '1 December 2015 - Present\n' 'Facebook\n' 'Founder and CEO\n' '4 February 2004 - Present\n' 'Palo Alto, California\n' 'Bringing the world closer together.'} To extract friends, pass the argument Group infoThe Usage: from facebook_scraper import get_group_info get_group_info("makeupartistsgroup") # or get_group_info("makeupartistsgroup", cookies="cookies.txt") Output: {'admins': [{'link': '/africanstylemagazinecom/?refid=18', 'name': 'African Style Magazine'}, {'link': '/connectfluencer/?refid=18', 'name': 'Everythingbrightandbeautiful'}, {'link': '/Kaakakigroup/?refid=18', 'name': 'Kaakaki Group'}, {'link': '/opentohelp/?refid=18', 'name': 'Open to Help'}], 'id': '579169815767106', 'members': 6814229, 'name': 'HAIRSTYLES', 'type': 'Public group'} To-Do
Alternatives and related projects
Is it possible to scrape Facebook posts?There is a great Python library called facebook-scraper which can make Facebook post data scraping much easier, without any additional dependencies or works with Beautify Soup 4 and re as usual. Facebook post data are including post text content, the number of likes, reactions, shares, comments, etc…
Is web scraping with Python legal?Scraping for personal purposes is usually OK, even if it is copyrighted information, as it could fall under the fair use provision of the intellectual property legislation. However, sharing data for which you don't hold the right to share is illegal.
How do you scrape a Facebook review?How to scrape Facebook pages' reviews?. Create a free Phantombuster account.. Connect to Facebook using PhantomBuster's browser extension.. Specify which Facebook pages' reviews you want to scrape.. Set the Phantom on repeat.. Download the Facebook reviews to a . CSV spreadsheet or a . JSON file.. How do I scrape Facebook posts data to Excel?Step 1:Get Access Token from the Facebook Graph API Explorer. ... . Step 2:Get your competitor's Facebook Fan Page ID from the Graph API. ... . Step 3:Pulling data from your competitor's Facebook page. ... . Step 4:Converting JSON file to CSV/Excel. ... . Step 5:Competitor analysis. ... . Step 6:Exporting Facebook posts comments to Excel.. |