Last active
November 23, 2019 05:23
-
-
Save gsscoder/be2f3d4b794a61e842e8af6c37dec36c to your computer and use it in GitHub Desktop.
Scrapes Facebook for 5 random persons in 5 random cities
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| fbscrap_5random.py: | |
| Demonstrates facebook_snooper package (https://github.com/gsscoder/facebook-snooper/). | |
| For version: 0.3.5 | |
| Usage: python3 fbscrap_5random | |
| """ | |
| from facebook_snooper import Session | |
| import requests | |
| import json | |
| import sys | |
| import random | |
| import getpass | |
| cities_json = requests.get( | |
| 'https://raw.githubusercontent.com/gsscoder/test-data/master/largest-cities.json') | |
| cities = json.loads(cities_json.content) | |
| names_json = requests.get( | |
| 'https://gist.githubusercontent.com/gsscoder/e0e905fbef23376aabfa695d85d8ef5c/raw/c250e439541647e3b2125922a04e1323ae51ff7a/names.json') | |
| names = json.loads(names_json.content) | |
| username = input('username: ') | |
| password = getpass.getpass() | |
| fb = Session.default() | |
| print('Attempting connection...') | |
| if not fb.log_in(username, password): | |
| sys.exit('Can\'t login to Facebook!') | |
| few_cities = cities[:5] | |
| few_names = names[:5] | |
| random.shuffle(few_cities) | |
| random.shuffle(few_names) | |
| for i, city in enumerate(few_cities): | |
| print(f'{city.upper()}:') | |
| print(f'{"=" * (len(city) + 1)}') | |
| person = few_names[i] | |
| query = f'{person} {city}' | |
| results = fb.search(query) | |
| for id, _, _ in results: | |
| name, image_link, followers, intro = fb.profile_info(id) | |
| print(f' {name} ({id}):') | |
| image = f'{image_link[:60]}...' if len(image_link) > 0 else "[NO IMAGE]" | |
| print(f' - image link: {image}') | |
| if len(followers) > 0: | |
| print(f' - followers: {int(followers)}:') | |
| if len(intro) == 0: | |
| print(' - [this profile takes care of privacy]') | |
| else: | |
| print(' INTRO:') | |
| print(' =====:') | |
| for info in intro: | |
| print(f' - {info}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment