SHARE
TWEET

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

furas May 30th, 2018 (edited) 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import requests
  2. import bs4
  3. import sys
  4.  
  5. g_session = requests.Session()
  6. #g_session.headers['User-Agent'] = 'Mozilla/52' # doesn't need it
  7.  
  8. DEBUG = True
  9.  
  10. def Login():
  11.     User = 'vananXX@gmail.com'
  12.     Pass = 'tienl0i123456'
  13.     url = 'https://id.unica.vn/login'
  14.  
  15.     try:
  16.         r = g_session.get(url)
  17.         if r.status_code != 200:
  18.             print("Loi server") # print instead of return
  19.             sys.exit(1)
  20.     except Exception as e:
  21.         print("Loi: %s - url: %s", e, url) # print instead of return
  22.         return False
  23.  
  24.     sauce = r.text # r.text
  25.  
  26.     soup = bs4.BeautifulSoup(sauce, 'lxml')
  27.    
  28.     #all_metas = soup.find_all('meta')
  29.     #authenticity_token = all_metas[0].get('content')
  30.  
  31.     first_metas = soup.find('meta')
  32.     authenticity_token = first_metas.get('content')
  33.  
  34.     if DEBUG:
  35.         #print('[DEBUG] all_metas:', all_metas)
  36.         print('[DEBUG] first_metas:', first_metas)
  37.         print('[DEBUG] authenticity_token:', authenticity_token)
  38.    
  39.     if not authenticity_token:
  40.         print("Vui long lien he nha phat trien") # print instead of return
  41.         return False
  42.  
  43.     payload = { 'email' : User, # wrong name
  44.                 'pass': Pass,   # wrong name
  45.                 '_csrf' : authenticity_token # wrong name and without [0]
  46.         }
  47.    
  48.     if DEBUG:
  49.         print('[DEBUG] payload:', payload)
  50.        
  51.     try:
  52.         r = g_session.post(url, data = payload)
  53.         if r.status_code != 200:
  54.             print("Loi dang nhap") # print instead of return
  55.             return False # add return
  56.     except Exception as e:
  57.         print("Loi: %s - url: %s", e, url) # print instead of return
  58.         return False
  59.  
  60.     if DEBUG:
  61.         print('[DEBUG] r.url:', r.url)
  62.         print('[DEBUG] r.history:', r.history)
  63.  
  64.     return r.url == 'https://unica.vn/home'
  65.  
  66.  
  67. # --- start ---
  68.  
  69. print(Login())
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top