自动化刷题小练习

驾校题库自动化刷题,使用了selenium以及requests等一些爬虫用的库

python 复制代码
from selenium import webdriver
from selenium.webdriver.common.by import By
import requests
import re
import time
driver=webdriver.Chrome()

driver.get("https://www.jsyks.com/kms-mnks")

question_list=driver.find_elements(By.CSS_SELECTOR,"div.Exam ul li")
print(question_list)

for li in question_list:
    answer_id=li.get_attribute("c")
    # print(answer_id)
    link=f'https://tiba.jsyks.com/Post/{answer_id}.htm'
    """
    通过 request获取数据
    """
    response=requests.get(link)
    html_data=response.text
    # print(html_data)
    a=re.findall('<br/>答案:<u>(.*?)</u>',html_data)[0]
#     获取答案内容
    bs=li.find_elements(By.CSS_SELECTOR,"b")
    for b in bs:
        choose=b.text
        if choose=="正确":
            choose="对"
        elif choose=="错误":
            choose="错"
        if len(choose)>2:
            choose=choose[0]
        for ans in a:
            if choose == ans:
                b.click()


submit=driver.find_element(By.CSS_SELECTOR,"div.ExamBtn u.btnJJ")
submit.click()
time.sleep(30)
相关推荐
代码老y22 分钟前
Docker:容器化技术的基石与实践指南
运维·docker·容器
典学长编程1 小时前
Linux操作系统从入门到精通!第二天(命令行)
linux·运维·chrome
烛阴2 小时前
简单入门Python装饰器
前端·python
好开心啊没烦恼2 小时前
Python 数据分析:numpy,说人话,说说数组维度。听故事学知识点怎么这么容易?
开发语言·人工智能·python·数据挖掘·数据分析·numpy
面朝大海,春不暖,花不开3 小时前
使用 Python 实现 ETL 流程:从文本文件提取到数据处理的全面指南
python·etl·原型模式
你想考研啊3 小时前
四、jenkins自动构建和设置邮箱
运维·jenkins
Code blocks3 小时前
使用Jenkins完成springboot项目快速更新
java·运维·spring boot·后端·jenkins
2301_805054564 小时前
Python训练营打卡Day59(2025.7.3)
开发语言·python
万千思绪4 小时前
【PyCharm 2025.1.2配置debug】
ide·python·pycharm
饥饿的半导体4 小时前
Linux快速入门
linux·运维