Guest User

Untitled

a guest
Mar 1st, 2014
135
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2.  
  3. import requests
  4. import re
  5.  
  6.  
  7. USER = 'login'
  8. PASSWORD = 'password'
  9.  
  10. BASEURL = 'https://www.linux.org.ru/'
  11. LOGIN_URL = BASEURL + '/login_process'
  12.  
  13.  
  14. def main():
  15.     session = requests.Session()
  16.    
  17.     csrf = session.get(LOGIN_URL).cookies.get('CSRF_TOKEN')[1:-1]
  18.  
  19.     session.post(LOGIN_URL, data=dict(nick=USER, passwd=PASSWORD, csrf=csrf))
  20.    
  21.     ptr = re.compile(r'{0}\((\d*)\)|{0}'.format(r'<span id="main_events_count">'))
  22.     result = ptr.search(session.get(BASEURL).text).group(1)
  23.  
  24.     print(0 if result is None else result)
  25.    
  26. if __name__ == '__main__':
  27.     main()
RAW Paste Data