furas

Python - https://id.unica.vn/login

May 30th, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. import requests
  2. import bs4
  3. import sys
  4.  
  5. g_session = requests.Session()
  6.  
  7. def Login():
  8.     User = 'vananXX@gmail.com'
  9.     Pass = 'tienl0i999999999'
  10.     url = 'https://id.unica.vn/login'
  11.     try:
  12.         r = g_session.get(url)
  13.         if r.status_code != 200:
  14.             print("Loi server") # print instead of return
  15.             sys.exit(1)
  16.     except Exception as e:
  17.         print("Loi: %s - url: %s", e, url) # print instead of return
  18.         return False
  19.  
  20.     sauce = r.text # r.text
  21.     soup = bs4.BeautifulSoup(sauce, 'lxml')
  22.     lst = []
  23.     for x in soup.find_all('meta'):
  24.         lst.append(x.get('content'))
  25.     authenticity_token = lst[0]
  26.     if not authenticity_token:
  27.         print("Vui long lien he nha phat trien") # print instead of return
  28.         return False
  29.     payload = { 'user[email]' : User,
  30.                 'user[password]': Pass,
  31.                 'csrf-token' : authenticity_token[0]
  32.         }
  33.     try:
  34.         r = g_session.post(url, data = payload)
  35.         if r.status_code != 200:
  36.             print("Loi dang nhap") # print instead of return
  37.             return False # add return
  38.     except Exception as e:
  39.         print("Loi: %s - url: %s", e, url) # print instead of return
  40.         return False
  41.  
  42.     return True
  43.  
  44. if Login():
  45.     print(True)
  46. else:
  47.     print(False)
Add Comment
Please, Sign In to add comment