Created
October 26, 2021 04:08
-
-
Save bitcoinmeetups/ab2dd4e55df9556f4622e8fcdefae16a to your computer and use it in GitHub Desktop.
Log into Facebook
This file contains 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
""" | |
Use BeautifulSoup to log into Facebook from the Terminal | |
""" | |
import requests | |
from bs4 import BeautifulSoup | |
url = 'https://www.facebook.com/login.php' | |
# Get the login page | |
r = requests.get(url) | |
# Parse the HTML | |
soup = BeautifulSoup(r.text, 'html.parser') | |
# Find the login form | |
form = soup.find('form', {'id': 'login_form'}) | |
# Get the form action | |
form_action = form.get('action') | |
# Get the form fields | |
form_fields = {} | |
for field in form.find_all('input'): | |
form_fields[field.get('name')] = field.get('value') | |
# Set the email and password | |
form_fields['email'] = '<your email>' | |
form_fields['pass'] = '<your password>' | |
# Post the form | |
r = requests.post(form_action, data=form_fields) | |
# Get the home page | |
r = requests.get('https://www.facebook.com/') | |
# Print the home page | |
print(r.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment