你还在担心期末复习没有题目做?爬虫帮帮你

Posted ZSYL

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了你还在担心期末复习没有题目做?爬虫帮帮你相关的知识,希望对你有一定的参考价值。

你还在为期末复习没有题目做?

前言

Python数据分析与可视化期末复习,因为是学校第一年考试,只能去互联网上找题啦!

给大家推荐一个宝藏级的考试系统,里面有各种计算机科目的练习题,可以直接在上面答题练习,也可以像我一样暴力输出。


题库刷题



暴力输出

暴力爬取全部题目信息及答案!

"""
@Author: ZS
@CSDN  : https://zsyll.blog.csdn.net/
@Time  : 2021/12/3 20:15
"""
import requests
import json

class Crawler(object):

    def __init__(self):
        self.url = 'https://www.qingline.net/api/question/'
        self.headers = 
            'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvYXBpLnFpbmdsaW5lLm5ldFwvYXBpXC9wY1wvbG9naW4iLCJpYXQiOjE2Mzg1MzI5OTksImV4cCI6MTY0MzcxNjk5OSwibmJmIjoxNjM4NTMyOTk5LCJqdGkiOiJUa2NJZWxzZnMyNUx5VGJkIiwic3ViIjoyODE2ODYsInBydiI6IjUxY2Q2ZWM3MDRhZjc2OGQ4NjNlZDkwZTVmNDJmZTg2MzkwNTU2ZmUifQ.N2lemtzF_7eeHHHYbJ9rTrnNZzIYx7FEzFuMEReH0N0'.encode('utf-8'),
            'Cookie': 'UM_distinctid=17d7f3e949e45c-05b2173be02be1-b7a1b38-e1000-17d7f3e949f574; CNZZDATA1279193991=1166429268-1638512935-|1638523747; token=Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvYXBpLnFpbmdsaW5lLm5ldFwvYXBpXC9wY1wvbG9naW4iLCJpYXQiOjE2Mzg1MzI5OTksImV4cCI6MTY0MzcxNjk5OSwibmJmIjoxNjM4NTMyOTk5LCJqdGkiOiJUa2NJZWxzZnMyNUx5VGJkIiwic3ViIjoyODE2ODYsInBydiI6IjUxY2Q2ZWM3MDRhZjc2OGQ4NjNlZDkwZTVmNDJmZTg2MzkwNTU2ZmUifQ.N2lemtzF_7eeHHHYbJ9rTrnNZzIYx7FEzFuMEReH0N0; userinfo="id":138065,"verified":null,"student_number":"195815614212","grade":3,"university_id":322,"phone":18625688543,"avatar_url":"http://thirdwx.qlogo.cn/mmopen/vIwUrAlxPObwXjriay5l9PNvGnicUvnrEM68yltYXZrTqM8We5DggYkyejxhnbx7WuNlibWV8nfhBabsxlsJO8sJAHqiaLOgaGsW/132","email":"1660730688@qq.com","real_name":"zs","rank":"","university_name":"清华大学","position":"","teacher_number":"","identity_number":"","nick_name":"","user_type":2,"department":"人工智能学院","major":"大数据"'.encode('utf-8'),
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (Khtml, like Gecko) Chrome/93.0.4542.2 Safari/537.36',
        
        self.md = open('./题目.md', 'w', encoding='utf-8')

    def get_data(self, i, index):
        response = requests.get(self.url+str(i), headers=self.headers)
        data = response.json()
        self.save(data, index)

    def save(self, data, index):
        # 题目描述
        self.md.writelines(f'#### index.' + data['data']['stem'] + '\\n')
        # 选项信息
        if 'options' in data['data'].keys():  #'options': ['id': 123652, 'content': 'Jupyter notebook可以直接生成一份交互式文档', 'question_id': 48204, 'order_number': 65, 'is_right_answer': 0, 'title': 'Jupyter notebook可以直接生成一份交互式文档', 'id': 12
            for option in data['data']['options']:
                self.md.writelines('- ' + option['content'] + '\\n')
        # 正确答案
        self.md.writelines('\\nright_answers: ' + data['data']['right_answers'][0]['content'] + '\\n')

        print(f'第index道题爬取完毕!')


if __name__ == '__main__':
    crawler = Crawler()
    index = 1
    for i in range(1, 255):
        crawler.get_data(48203+i, index)
        index += 1

    for i in range(22):
        crawler.get_data(48463+i, index)
        index += 1

    crawler.md.close()
    

结果展示

【Python数据分析与可视化】期末复习试题集

发给咱 美丽 动人 可爱 优秀 大方的学委小姐姐


呜呜呜~


加油!

感谢!

努力!

以上是关于你还在担心期末复习没有题目做?爬虫帮帮你的主要内容,如果未能解决你的问题,请参考以下文章

修理厂还在担心黑客入侵OBD测试工具?因为你还没用过这样的DIY硬件小工具

codevs 2915 期末考试

Oracle期末复习资料,不用再担心考试啦!

Oracle期末复习资料,不用再担心考试啦!

Oracle期末复习资料,不用再担心考试啦!

教你使用java的爬虫爬取你想要的资源