Advertisement
Guest User

LORlogin

a guest
Jan 20th, 2014
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. import urllib
  2. import http
  3. from http import cookiejar
  4.  
  5. CSRF_LEN = 24
  6. cookie = None
  7. opener = None
  8. csrf = None
  9. logged = False
  10. nick = 'anonymous'
  11. passwd = ''
  12.  
  13. def get_csrf():
  14.     html = opener.open('https://www.linux.org.ru').read().decode('utf-8')
  15.     marker = 'name="csrf" value="'
  16.     start_pos = html.find(marker) + len(marker)
  17.     end_pos = start_pos + CSRF_LEN
  18.     return html[start_pos:end_pos]
  19.  
  20. def init():
  21.     global cookie, opener, csrf
  22.     cookie = http.cookiejar.CookieJar()
  23.     opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cookie))
  24.     csrf = get_csrf()
  25.  
  26. def login(nickname, password):
  27.     global csrf, nick, passwd, logged
  28.     csrf = get_csrf()
  29.     nick = nickname
  30.     passwd = password
  31.     par = urllib.parse.urlencode({
  32.         'csrf': csrf,
  33.         'nick': nick,
  34.         'passwd': passwd}).encode('utf-8')
  35.     resp = opener.open('https://www.linux.org.ru//login_process', par)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement