Skip to content

Instantly share code, notes, and snippets.

@Henrique-Miranda
Last active October 6, 2021 02:36
Show Gist options
  • Save Henrique-Miranda/a0f51184b4dc87934100d4aa9de3fe70 to your computer and use it in GitHub Desktop.
Save Henrique-Miranda/a0f51184b4dc87934100d4aa9de3fe70 to your computer and use it in GitHub Desktop.
Make login on facebook usind python requests. Dont work with 2fa protection. 03/08/2019
import sys
try:
import requests
except:
print('Please install requests: "pip install requests"')
sys.exit()
try:
from bs4 import BeautifulSoup as bs
except:
print('Please install BeautifulSoup: "pip install bs4"')
sys.exit()
if len(sys.argv) < 3:
print("Usage: python3 facelogin.py email password")
sys.exit()
# Faz a primeira request para pegar os dados randômicos do form
url = 'https://m.facebook.com/login.php'
html = requests.get(url).text
HTML = bs(html, 'html.parser')
payload = {}
email = sys.argv[1]
passwd = sys.argv[2]
r = HTML.findAll('input')
for i in r:
payload[i.get('name')] = i.get('value')
payload['email'] = email
payload['pass'] = passwd
payload['login'] = 'Log In'
# print(payload)
# Cria uma session para manter os dados do login.
s = requests.Session()
r = s.post(url, data=payload, allow_redirects=False)
r.raise_for_status()
cookies = r.cookies
# print(cookies)
# Proximas requests será atravéz da session s.get(URL)
home = s.get('https://m.facebook.com', cookies=cookies, allow_redirects=False)
bhtml = bs(home.text, 'html.parser')
#print(bhtml)
# Procura pelo link SAIR para saber se o login foi efetuado
logged = bhtml.find('a', {'id': 'mbasic_logout_button'})
try:
if logged.text:
print(f"Login efetuado, usuário: {logged.text.split('(')[1].replace(')', '')}")
except:
print("Login e/ou senha incorretos")
@Henrique-Miranda
Copy link
Author

Don't work if the account use 2fa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment