Skip to content

Instantly share code, notes, and snippets.

@gsscoder
Last active November 23, 2019 05:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsscoder/1708235c2d6a47b4473e046c4afae7ae to your computer and use it in GitHub Desktop.
Save gsscoder/1708235c2d6a47b4473e046c4afae7ae to your computer and use it in GitHub Desktop.
Scrapes Facebook to gather profile IDs
"""
fbscrap_getIDs.py:
Used to gather real Facebook profile IDs (https://github.com/gsscoder/facebook-snooper/).
For version: 0.4.3
Usage: python3 fbscrap_getIDs output_file.txt
"""
import requests
import json
import sys
import random
import getpass
import facebook_snooper
names_json = requests.get(
'https://gist.githubusercontent.com/gsscoder/e0e905fbef23376aabfa695d85d8ef5c/raw/c250e439541647e3b2125922a04e1323ae51ff7a/names.json')
names = json.loads(names_json.content)
random.shuffle(names)
username = input('username: ')
password = getpass.getpass()
all_ids = []
print('Attempting connection...')
try:
with facebook_snooper.default_session() \
.log_in(username, password) as fb:
for name in names[:10]:
print(f'Searching Profile IDs for {name}.')
results = fb.search(name)
ids = [id for id, _, _ in results]
all_ids.extend(ids)
with open(sys.argv[1], 'w') as out:
out.write('\n'.join(all_ids))
except Exception as err:
sys.stderr.write(f'ERROR: {err}\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment