Python realizes the automatic answering of the driving test, 100 points is not too simple.....

Hello everyone, I am a red panda ❤

I don't know if everyone has passed the driver's license?

Whether you have this driver's license or not, I believe everyone has this:

Please add image description

My friend is taking a driver's license test recently, and he is about to take the test...

I smiled and gave him the whole life on the spot~

Using Python to complete dozens of lines of code, to achieve automatic answering questions for friends~

I said when you answer the question so fast, I'll buy you a car!

Hey, quietly tell you, that is impossible, if you don't believe me, watch the case demonstration!

Please add image description

Demonstration of case effect

原速未加速

Please add image description

Code display

代码仅做展示

I blocked the URL, otherwise the system will not give it~

module

import requests
import parsel
from selenium import webdriver

Please add image description

send request

insert image description here

get answer link

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

Please add image description

get answers

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

Get all your questions and answers

def get_all_answer(answer_url_list):
    """
    
    :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)

Today's article is here~

I'm Red Panda, see you in the next article (✿◡‿◡)

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

Finally, I recommend a set of Python videos for you:

Please three! [It only takes 12 hours, and the monthly income of the sideline exceeds 10,000] The new version of python ship, entry can be punished

Please add image description

Guess you like

Origin blog.csdn.net/m0_67575344/article/details/127089830