Skip to content

Instantly share code, notes, and snippets.

@manu-chroma
Created February 11, 2016 19:13
Show Gist options
  • Save manu-chroma/64ca625d929e89297b74 to your computer and use it in GitHub Desktop.
Save manu-chroma/64ca625d929e89297b74 to your computer and use it in GitHub Desktop.
note: mechanize doesn't support python 3
import mechanize
from bs4 import BeautifulSoup as bs
from getpass import getpass
#USER CREDENTIALS
email = raw_input("email: ")
password = getpass("password: ")
#GETTING SOURCE CODE
browser = mechanize.Browser()
browser.set_handle_robots(False)
browser.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.41 Safari/534.7')]
browser.open("http://m.facebook.com/")
browser.select_form(nr=0)
browser.form['email'] = email
browser.form['pass'] = password
response = browser.submit()
#PARSER
soup = bs(response.read(),"lxml")
soup = soup.find("label", {"for" : "u_0_0"})
username = soup.a
username.clear()
print (username)
#to do: exception handling for wrong credentials
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment