Facebook Page Follower Scrap (mobile)
Overview
This script automates the process of scraping Facebook profile information from follower lists and saving it to a Google Sheet. It uses Appium for mobile automation and interacts with the Facebook mobile app to extract profile links and user IDs.
Key Features
Automated navigation through Facebook follower lists
Extraction of profile links and user IDs
Storage of collected data in Google Sheets
Smart duplicate detection and skipping
Error handling and retry mechanisms
Telegram notifications for critical errors
Prerequisites
Appium Setup: Requires Appium server and Android device/emulator setup
Google Cloud Credentials:
Enable Google Sheets API and Google Drive API
Create a service account and download credentials JSON
Share your Google Sheet with the service account email
Python Dependencies: pip install appium-python-client selenium gspread google-auth requests
Configuration
Edit these variables at the top of the script:
sheet_name = " " # Worksheet name
spreadsheet_name = " " # Google Sheet name
start = " " # The first name in follower list
How It Works
Initialization
Starts Appium driver session
Loads existing data from Google Sheet to avoid duplicates
Navigation Flow
Finds and clicks target profile by content description
Navigates to follower list
Iterates through followers:
Clicks each follower
Extracts profile information
Returns to follower list
Continues to next follower
Data Extraction
For each profile:
Clicks "See more" options
Selects "Share profile"
Copies profile link
Processes link to get:
Clean final URL (after redirects)
Facebook user ID (extracted from page source)
Data Storage
Stores collected data in Google Sheets with columns:
Name (content description)
ID (Facebook user ID)
Profile_link (clean URL)
Usage Instructions
Initial Setup:
Configure your Google credentials (see Configuration section)
Set up Appium with connected Android device
Log in to Facebook on the device
Running the Script: python facebook_scrapper.py
Resuming Progress:
The script automatically checks the last stored entry in Google Sheets
To start from a specific profile, modify the startpoint in main()
Step Flow
Step 1 - Connect Your Android Device
Enable USB Debugging on your Android device (Settings > Developer Options).
Connect the device to your computer via USB (or use an emulator like Android Studio).
Verify connection with: adb devices (Should list your device.) note: open terminal at this path (example: C:\Users\IM11\AppData\Local\Android\Sdk)

Step 2 - Start Appium Server
Run Appium in a terminal: appium (Keep this running in the background.)

Step 3 - Run the Script
Execute the script: python facebook_scrapper.py

Step 4 - Monitoring Progress
Check the terminal logs for real-time updates
Example log:
[1] Clicking ViewGroup with content-desc: John Doe
✅ Extracted ID: 123456789
✅ Appended 1 new entry to Google Sheets.
Open Google Sheets to see collected data populate.
Step 5 - Stopping the Script
Press Ctrl + C in the terminal to stop the script safely.
The script will save the last processed profile for resuming later.
Functions Breakdown
Core Functions
run_scraper(startpoint): Main loop that handles profile navigation and data collection
get_profile_link(driver): Extracts profile link via UI interaction
get_facebook_url_and_id(url): Resolves final URL and extracts user ID
save_to_google_sheet(driver, data): Saves collected data to Google Sheets
Helper Functions
click_by_content_desc(): Clicks UI elements by content description
get_content_desc_safe(): Safely gets content description with retries
scroll_down(): Performs scroll gesture
is_on_follower_list_page(): Detects current page context
send_telegram_message(): Sends error notifications
Limitations
Requires Facebook mobile app UI to remain relatively stable
Performance depends on network speed and device capabilities
May require adjustments for different Facebook language settings
Possible Issues
Facebook version This scrapper may not work with the latest version of Facebook. To address this , please download an older version of Facebook.
Content Description Error The ‘...’, ‘share’ or ‘copy’ in the devices cannot be clicked. It happens because the content description is different on different devices. To address this, please check the function def get_profile_link(driver), add in or replace the words that are found through the ui automator viewer.
Example error:
❌ Failed to click '查看更多'
❌ Failed to click '分享個人檔案'
❌ Failed to click '複製連結'
Code:
def get_profile_link(driver):
try:
time.sleep(2)
if not click_by_content_desc(driver, ["查看更多", "查看選項", "显示选项", "See more", "See options", "查看更多個人檔案設定"]):
print("❌ Failed to click '查看更多'")
return None, None
time.sleep(1)
if not click_by_content_desc(driver, ["分享個人檔案", "分享个人主页", "Share profile"]):
print("❌ Failed to click '分享個人檔案'")
return None, None
time.sleep(1)
if not click_by_content_desc(driver, ["複製連結", "复制链接", "Copy link"]):
print("❌ Failed to click '複製連結'")
return None, None
time.sleep(1)
link = driver.execute_script("mobile: getClipboard")
print("📋 Copied link:", link)
try:
decoded_link = base64.b64decode(link).decode('utf-8')
print("🔓 Decoded link:", decoded_link)
final_url, fb_id = get_facebook_url_and_id(decoded_link)
except Exception:
print("🔗 Link not base64 encoded, using original.")
final_url, fb_id = get_facebook_url_and_id(link)
print(f"🔗 Final URL: {final_url}")
print(f"🆔 Facebook ID: {fb_id}")
return final_url, fb_id
except Exception as e:
print("❌ Error getting profile link:", e)
return None, None
UI Automator Viewer
please refer to these:
Last updated