自动化刷题小练习

驾校题库自动化刷题,使用了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)
相关推荐
鹿鹿学长1 小时前
国赛备赛第一课:高数、线代、概率统计在历年赛题中的真实出镜率盘点
python·自动化
整个江湖1 小时前
Python 工程实践:时间区间解析、时区归一化与边界测试
python
2501_909509101 小时前
DAY 43
python
FinelyYang1 小时前
CentOS 7.6 自建 LiveKit 部署指南
linux·运维·centos
Huangjin007_1 小时前
【Linux 系统篇(十四)】进程 (二) :PCB、task_struct、fork系统调用
linux·运维·服务器
HiDev_1 小时前
【非标自动化】硬核阅读理解620行梯形图(70~619行)
运维·自动化
weixin_471383031 小时前
07 LangGraph 集成 RAG
python·langchain·agent·langgraph
维度攻城狮1 小时前
PyCharm 使用 DevContainer 开发:打造一致、隔离、高效的开发环境
ide·python·pycharm·devcontainer
七夜zippoe1 小时前
OpenClaw 测试策略实战:AI Agent 自动化测试体系搭建与落地
人工智能·ai·自动化·agent·测试体系·openclaw
ctlover2 小时前
Python模块与包
开发语言·python