自动化刷题小练习

驾校题库自动化刷题,使用了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)
相关推荐
linweidong几秒前
在Ubuntu新版本安装gcc4.8等老版本环境
linux·运维·ubuntu
love530love5 分钟前
EPGF 新手教程 21把“环境折磨”从课堂中彻底移除:EPGF 如何重构 AI / Python 教学环境?
人工智能·windows·python·重构·架构·epgf
ldccorpora6 分钟前
Chinese News Translation Text Part 1数据集介绍,官网编号LDC2005T06
数据结构·人工智能·python·算法·语音识别
大学生毕业题目6 分钟前
毕业项目推荐:99-基于yolov8/yolov5/yolo11的肾结石检测识别系统(Python+卷积神经网络)
人工智能·python·yolo·目标检测·cnn·pyqt·肾结石检测
寄思~8 分钟前
Excel 数据匹配工具 -笔记
笔记·python·学习·excel
jarreyer14 分钟前
【docker的gpu加速相关问题解决记录】
运维·docker·容器
石像鬼₧魂石15 分钟前
80 端口(Web 服务)渗透测试完整总结(含踩坑 + 绕过 + 实战流程)
linux·运维·服务器·前端·网络·阿里云
韭菜钟17 分钟前
制作自定义Docker镜像并部署使用
运维·docker·容器
米高梅狮子22 分钟前
11. Linux 防火墙管理
linux·运维·服务器
小五传输37 分钟前
网闸怎么选?新型网闸凭安全高效,成企业优选方案
大数据·运维·安全