• Python骚操作,实现驾考自动答题,这就直接满分了?


    Python骚操作来了~

    用Python来实现科目一/四自动答题,100分不要太简单!

    最初是表弟最近想买车,但是驾照都没有,买什么车,只能先考驾照~

    看他在网页上练习题目慢吞吞的,我就看不下去了,直接给他来一手揠苗助长~

    当时就用Python整了几十行代码,给他实现一下自动答题,我说你什么时候答题这么快,我就给你买个车!

    嘿嘿,悄悄告诉你们,那是不可能的,不信你们看案例演示!

    案例效果演示

    就这速度,我可没加速哈~

    在这里插入图片描述

    代码展示

    代码仅做展示

    网址我屏蔽了,不然系统不给过~

    模块

    import requests
    import parsel
    from selenium import webdriver

    发送请求

    def get_response(html_url):
        """
        :param html_url: 请求网址
        :return: 响应对象
        """
        headers = {
            'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36'
        }
        response = requests.get(url=html_url, headers=headers)
        return response

    获取答案链接

    def get_answer_url(html_url):
        """
        :param html_url:
        :return:
        """
        html_data = get_response(html_url).text
        selector = parsel.Selector(html_data)
        answer_url_id = selector.css('.Content li::attr(c)').getall()
        answer_url_list = [f'https://地址我屏蔽了,不然不给过/Post/{i}.htm' for i in answer_url_id]
        return answer_url_list

    获取答案

    def get_answer_result(answer_url):
        """
        
        :param answer_url:
        :return:
        """
        answer_data = get_response(html_url=answer_url).text
        selector = parsel.Selector(answer_data)
        question = selector.css('#question a::text').get()
        answer = selector.css('#question h1 u::text').get()
        if answer == '':
            answer = '正确'
        elif answer == '':
            answer = '错误'
    
        answer_dict = {
            '问题': question,
            '答案': answer
        }
        return answer_dict

    获取所有问题以及答案

    def get_all_answer(answer_url_list):
        """
        完整源码都放在这个裙了 279199867
        :param link:
        :return:
        """
        page = 1
        for answer_url, li in zip(answer_url_list, lis):
            answer_dict = get_answer_result(answer_url)
            bs = li.find_elements_by_css_selector('b')
            num = 1
            for b in bs:
                choose = b.text
                if len(choose) > 2:
                    choose = choose[0]
                print(choose, answer_dict['答案'])
                if choose in answer_dict['答案']:
                    driver.find_element_by_css_selector(f'#LI{page} b:nth-child({num+2})').click()
                    print('点击了')
                else:
                    print('没有点击')
                num += 1
            page += 1
            print(answer_dict)

    完整源代码下方名片获取哈~

  • 相关阅读:
    Csharp: ASP.NET Core 3.1 Razor Pages Query and Pagination
    人脸识别示例
    C# 调用WCF服务的两种方法
    linux磁盘空间满处理情况
    linux上PGI编译器安装
    jeecgboot中自定义sql分页实现
    顺畅访问github的一种新思路和方案
    eduYouke在线教育点播系统
    基于SpringBoot的在线教育系统【源码开源】【建议收藏】
    解决ThinkPHP6 控制器不存在:app\controller\Index
  • 原文地址:https://www.cnblogs.com/hahaa/p/16732352.html
Copyright © 2020-2023  润新知