Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import bs4
- import sys
- g_session = requests.Session()
- #g_session.headers['User-Agent'] = 'Mozilla/52' # doesn't need it
- DEBUG = True
- def Login():
- User = 'vananXX@gmail.com'
- Pass = 'tienl0i123456'
- url = 'https://id.unica.vn/login'
- try:
- r = g_session.get(url)
- if r.status_code != 200:
- print("Loi server") # print instead of return
- sys.exit(1)
- except Exception as e:
- print("Loi: %s - url: %s", e, url) # print instead of return
- return False
- sauce = r.text # r.text
- soup = bs4.BeautifulSoup(sauce, 'lxml')
- #all_metas = soup.find_all('meta')
- #authenticity_token = all_metas[0].get('content')
- first_metas = soup.find('meta')
- authenticity_token = first_metas.get('content')
- if DEBUG:
- #print('[DEBUG] all_metas:', all_metas)
- print('[DEBUG] first_metas:', first_metas)
- print('[DEBUG] authenticity_token:', authenticity_token)
- if not authenticity_token:
- print("Vui long lien he nha phat trien") # print instead of return
- return False
- payload = { 'email' : User, # wrong name
- 'pass': Pass, # wrong name
- '_csrf' : authenticity_token # wrong name and without [0]
- }
- if DEBUG:
- print('[DEBUG] payload:', payload)
- try:
- r = g_session.post(url, data = payload)
- if r.status_code != 200:
- print("Loi dang nhap") # print instead of return
- return False # add return
- except Exception as e:
- print("Loi: %s - url: %s", e, url) # print instead of return
- return False
- if DEBUG:
- print('[DEBUG] r.url:', r.url)
- print('[DEBUG] r.history:', r.history)
- return r.url == 'https://unica.vn/home'
- # --- start ---
- print(Login())
Add Comment
Please, Sign In to add comment