ITIS Knowledge Test Backup

in Shares with 1 comment

Done:

Simple collection and process
Only include the questions i've done before
Duplicates exist

To-Do:

Import to database
Delete Duplicates

Week2

https://heiybb.com/ITIS/Week-2-1.html
https://heiybb.com/ITIS/Week-2-2.html
https://heiybb.com/ITIS/Week-2-3.html

Week3

https://heiybb.com/ITIS/Week-3-1.html
https://heiybb.com/ITIS/Week-3-2.html
https://heiybb.com/ITIS/Week-3-3.html

Week4

https://heiybb.com/ITIS/Week-4-1.html
https://heiybb.com/ITIS/Week-4-2.html

Week5

https://heiybb.com/ITIS/Week-5-1.html
https://heiybb.com/ITIS/Week-5-2.html
https://heiybb.com/ITIS/Week-5-3.html

Week6

https://heiybb.com/ITIS/Week-6.html

Week7

https://heiybb.com/ITIS/Week-7-1.html
https://heiybb.com/ITIS/Week-7-2.html
https://heiybb.com/ITIS/Week-7-3.html

Week8

https://heiybb.com/ITIS/Week-8-1.html
https://heiybb.com/ITIS/Week-8-2.html
https://heiybb.com/ITIS/Week-8-3.html

Week9

https://heiybb.com/ITIS/Week-9-1.html
https://heiybb.com/ITIS/Week-9-2.html
https://heiybb.com/ITIS/Week-9-3.html

Week10

https://heiybb.com/ITIS/Week-10-1.html
https://heiybb.com/ITIS/Week-10-2.html

Week11

https://heiybb.com/ITIS/Week-11.html

ALL-IN-ONE

https://heiybb.com/ITIS/ALL.txt

Core Code @XIAOYU

class TEST(HTMLParser):
    def reset(self):
        self.QLIST = []
        self.is_qnum = False
        self.is_question = False
        self.is_answer = False
        self.is_right_answer = False
        HTMLParser.reset(self)

    def handle_starttag(self, tags, attrs):
        for k, v in attrs:
            if k == 'class' and v == 'name question_name':
                self.is_qnum = True
                return

            if k == 'class' and v == 'question_text user_content enhanced':
                self.is_question = True
                return

            if k == 'class' and v == 'answer_text':
                self.is_answer = True
                return

            if k == 'title' and 'This was the correct answer' in v:
                self.is_right_answer = True
                return

    def handle_endtag(self, tag):
        self.is_qnum = False
        self.is_question = False
        self.is_answer = False
        self.is_right_answer = False

    def handle_data(self, data):
        if self.is_qnum:
            self.QLIST.append('\n' + data.strip())

        if self.is_question:
            self.QLIST.append(data.strip())

        if self.is_answer:
            self.QLIST.append(data.strip())

        if self.is_right_answer:
            self.QLIST.append('## Correct Below ##')

    def printQA(self):
        for i in self.QLIST:
            if i.strip() == '':
                self.QLIST.remove(i)
        for i in self.QLIST:
            print(i)
Responses
  1. Cache Test
    缓存测试

    Reply