Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import urllib
- import http
- from http import cookiejar
- CSRF_LEN = 24
- cookie = None
- opener = None
- csrf = None
- logged = False
- nick = 'anonymous'
- passwd = ''
- def get_csrf():
- html = opener.open('https://www.linux.org.ru').read().decode('utf-8')
- marker = 'name="csrf" value="'
- start_pos = html.find(marker) + len(marker)
- end_pos = start_pos + CSRF_LEN
- return html[start_pos:end_pos]
- def init():
- global cookie, opener, csrf
- cookie = http.cookiejar.CookieJar()
- opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cookie))
- csrf = get_csrf()
- def login(nickname, password):
- global csrf, nick, passwd, logged
- csrf = get_csrf()
- nick = nickname
- passwd = password
- par = urllib.parse.urlencode({
- 'csrf': csrf,
- 'nick': nick,
- 'passwd': passwd}).encode('utf-8')
- resp = opener.open('https://www.linux.org.ru//login_process', par)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement