Advertisement
Guest User

Untitled

a guest
Feb 14th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. import requests
  2. from getpass import getpass
  3.  
  4. URL = 'http://example.com'
  5.  
  6.  
  7. def login(session):
  8. user = input('Username: ')
  9. passwd = getpass('Password: ')
  10.  
  11. params = {
  12. 'action': 'do_login',
  13. }
  14. data = {
  15. 'quick_login': '1',
  16. 'quick_username': user,
  17. 'quick_password': passwd,
  18. }
  19.  
  20. headers = {'content-type': 'application/x-www-form-urlencoded'}
  21.  
  22. ret = session.post(URL + '/member.php', params=params, data=data, headers=headers)
  23. return ret
  24.  
  25.  
  26. def newreply(session, thread_id, message='Hello World'):
  27. params = {
  28. 'tid': thread_id,
  29. 'acton': 'do_newreply',
  30. }
  31. headers = {'content-type': 'application/x-www-form-urlencoded'}
  32.  
  33. data = {
  34. 'message_new': message,
  35. 'submit': 'New Reply',
  36. 'subject': 'test',
  37. }
  38.  
  39. ret = session.post(URL + '/newreply.php', params=params, data=data, headers=headers)
  40.  
  41. return ret
  42.  
  43.  
  44. if __name__ == '__main__':
  45. with requests.session() as session:
  46. ret_login = login(session)
  47. ret_reply = newreply(session, 3973)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement