Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import mechanize
- import time
- def foo():
- url = 'http://sibears.ru/training/qctf_quiz/'
- br = mechanize.Browser()
- response_str = br.open(url).read()
- dict = {}
- level = 1
- question = ''
- possible_answers = []
- # while level < 2785:
- while level < 100:
- try:
- new_question = response_str.split('<div class="header">', 1)[1].split('</div>')[0]
- new_level = int(new_question.split('/')[0])
- if new_level == 1:
- question = new_question
- level = 1
- if new_level > level:
- dict[question] = answer
- possible_answers = list()
- question = new_question
- level = new_level
- #print question
- try:
- answer = dict[question]
- except Exception:
- answer = next(possible_answers)
- br.follow_link(text=answer)
- response_str = br.response().read()
- except Exception:
- possible_answers = iter([link.text for link in br.links()])
- continue
- if __name__ == '__main__':
- start_time = time.time()
- foo()
- print time.time() - start_time
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement