0
点赞
收藏
分享

微信扫一扫

智慧树题库生成脚本,直接运行即可

晴儿成长记 2022-04-21 阅读 60
python爬虫
#!/usr/bin/env python
# encoding: utf-8
'''
@author: JHC
@license: None
@contact: JHC000abc@gmail.com
@file: spider.py
@time: 2022/3/15 13:12
@desc:智慧树题库爬虫
'''
import requests

def get_exerciseId_list(url):
    res = requests.get(url)
    exerciseId_list = [i["exerciseId"] for i in res.json()["rt"]["lists"]]
    return exerciseId_list

def get_content(exerciseId_list):

    INDEX = 1
    for questionId in exerciseId_list:
        params = (
            ('courseId', '10464858'),
            ('questionId', questionId),
            ('times', '1'),
            ('randomExerciseStyle', '0'),
            ('uuid', 'Vj1vy1A7'),
        )

        response = requests.get('https://hike-examstu.zhihuishu.com/zhsathome/randomExercise/queryRandomExerciseDetail',
                                 params=params)
        # print(response.json())
        questionType = response.json()["rt"]["questionName"]
        if questionType == '单选题':
            content = response.json()["rt"]["content"]
            print("[单选题] "+str(INDEX)+'. '+ str(content).replace(" ",'\t'))
            optionList = response.json()["rt"]["optionList"]
            flag = 1
            for option in optionList:
                option_content = option["content"]
                if flag == 1:
                    single = 'A. '
                if flag == 2:
                    single = 'B. '
                if flag == 3:
                    single = 'C. '
                if flag == 4:
                    single = 'D. '
                print('\t\t'+single + option_content)

                flag += 1
            print('\n')
        if questionType == '多选题':
            content = response.json()["rt"]["content"]
            print("[多选题] "+str(INDEX)+'. '+str(content).replace(" ",'\t'))
            optionList = response.json()["rt"]["optionList"]
            flag = 1
            for option in optionList:
                option_content = option["content"]
                if flag == 1:
                    single = 'A. '
                if flag == 2:
                    single = 'B. '
                if flag == 3:
                    single = 'C. '
                if flag == 4:
                    single = 'D. '
                if flag == 5:
                    single = 'E. '
                if flag == 6:
                    single = 'F. '
                print('\t\t'+single+option_content)
                flag += 1
            print('\n')
        if questionType == '判断题':
            content = response.json()["rt"]["content"]
            print("[判断题] " +str(INDEX)+'. '+ str(content).replace(" ",'\t'))
            print('\n')
        INDEX += 1

if __name__ == '__main__':
    url = 'https://hike-examstu.zhihuishu.com/zhsathome/randomExercise/queryAnswerSheet?courseId=10464858&isFirst=true&randomExerciseStyle=0&uuid=Vj1vy1A7'
    get_content(get_exerciseId_list(url))

定做其他科目请邮件私聊

举报

相关推荐

0 条评论