Advertisement
Guest User

Untitled

a guest
May 6th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. import mechanize
  2. import time
  3.  
  4. def foo():
  5. url = 'http://sibears.ru/training/qctf_quiz/'
  6.  
  7. br = mechanize.Browser()
  8. response_str = br.open(url).read()
  9.  
  10. dict = {}
  11. level = 1
  12. question = ''
  13. possible_answers = []
  14.  
  15. # while level < 2785:
  16. while level < 100:
  17. try:
  18. new_question = response_str.split('<div class="header">', 1)[1].split('</div>')[0]
  19. new_level = int(new_question.split('/')[0])
  20.  
  21. if new_level == 1:
  22. question = new_question
  23. level = 1
  24.  
  25. if new_level > level:
  26. dict[question] = answer
  27. possible_answers = list()
  28. question = new_question
  29. level = new_level
  30. #print question
  31.  
  32. try:
  33. answer = dict[question]
  34. except Exception:
  35. answer = next(possible_answers)
  36.  
  37. br.follow_link(text=answer)
  38. response_str = br.response().read()
  39. except Exception:
  40. possible_answers = iter([link.text for link in br.links()])
  41. continue
  42.  
  43. if __name__ == '__main__':
  44. start_time = time.time()
  45. foo()
  46. print time.time() - start_time
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement