Extract email from facebook group script

Here is a script that extracts email addresses from a Facebook group:

import requests
import re
from bs4 import BeautifulSoup

# Replace with your Facebook group URL
group_url = "https://www.facebook.com/groups/yourgroupname"

# Send a GET request to the group page
response = requests.get(group_url)

# Parse the HTML content using BeautifulSoup
soup = BeautifulSoup(response.content, 'html.parser')

# Find all the email addresses on the page
emails = re.findall(r"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}", str(soup))

# Print the extracted email addresses
for email in emails:
    print(email)

This script uses the requests library to send a GET request to the Facebook group page, and then uses the BeautifulSoup library to parse the HTML content. It then uses a regular expression to find all the email addresses on the page, and prints them out.

Note that this script may not work if the Facebook group uses a custom domain or has email addresses hidden behind a login wall. Additionally, Facebook's terms of service prohibit scraping email addresses, so be sure to check their policies before running this script.

Also, you can use Facebook Graph API to extract email addresses from a Facebook group, you can use the following endpoint:

https://graph.facebook.com/v13.0/{group_id}/members?fields=email&access_token={access_token}

You need to replace {group_id} with the actual ID of the Facebook group, and {access_token} with a valid access token that has the email permission.

You can use the following Python script to extract email addresses using Facebook Graph API:

import requests

# Replace with your Facebook group ID and access token
group_id = "your_group_id"
access_token = "your_access_token"

# Send a GET request to the Facebook Graph API
response = requests.get(f"https://graph.facebook.com/v13.0/{group_id}/members?fields=email&access_token={access_token}")

# Parse the JSON response
data = response.json()

# Extract the email addresses
emails = [member["email"] for member in data["data"]]

# Print the extracted email addresses
for email in emails:
    print(email)

This script uses the requests library to send a GET request to the Facebook Graph API, and then parses the JSON response to extract the email addresses.