Guest User

Untitled

a guest
Dec 11th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. import re
  2. import requests
  3. from pyquery import PyQuery as pq
  4.  
  5.  
  6. def main(username, password):
  7. session = requests.session()
  8.  
  9. dtsg = login(session, username, password)
  10.  
  11.  
  12. def login(session, username, password):
  13. '''
  14. Login to Facebook
  15. '''
  16.  
  17. # Navigate to the Facebook homepage
  18. response = session.get('https://facebook.com')
  19.  
  20. # Construct the DOM
  21. dom = pq(response.text)
  22. # Get the lsd value from the HTML. This is required to make the login request
  23. lsd = dom('[name="lsd"]').val()
  24. # Perform the login request
  25. response = session.post('https://www.facebook.com/login.php?login_attempt=1', data={
  26. 'lsd': lsd,
  27. 'email': username,
  28. 'pass': password,
  29. 'default_persistent': '0',
  30. 'timezone': '-60',
  31. 'lgndim': '',
  32. 'lgnrnd': '',
  33. 'lgnjs': '',
  34. 'locale': 'en_GB',
  35. 'qsstamp': ''
  36. })
  37. dom1 = pq(response.text)
  38. #print(dom1)
  39. try:
  40. #dtsg = re.search('_4rbf _53ij', response.content)
  41. print(response.content)
  42. except KeyError:
  43. raise Exception('Login Failed!')
  44. #print(dtsg)
  45. #return dtsg
  46.  
  47. try:
  48. main(username='', password='')
  49. except Exception as e:
  50. print(e)
  51.  
  52. #it's important to mention that the Code was written by someone else, i changed it a little bit.
Add Comment
Please, Sign In to add comment