自动化刷题小练习

驾校题库自动化刷题,使用了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)
相关推荐
赵文宇(温玉)2 分钟前
Docker离线安装
运维·docker·容器
ZhengEnCi9 分钟前
前端日志和后端日志怎么记:分级、JSON 格式、按天分文件与保留策略
前端·后端·python
进击的荆棘19 分钟前
Linux网络——传输层协议UDP
linux·运维·服务器·网络·udp
Android系统攻城狮2 小时前
FFmpeg深度解析之av_bsf_get_by_name:如何查找码流过滤器?(七十九)
linux·运维·ffmpeg·音视频进阶·ffmpeg音视频
Decay__3 小时前
PostgreSQL 监控体系构建 —— postgres_exporter + Prometheus + Grafana 全栈实战
运维·数据库·sql·postgresql
Decay__4 小时前
PostgreSQL 告警与自动化运维 —— 告警分级收敛、Webhook、定时巡检、脚本库
运维·数据库·sql·postgresql
用户0332126663674 小时前
使用 Python 为 PDF 文件添加页眉页脚
python
xurileidian4 小时前
第 17 篇 · 边玩边学Python · for 遍历 enumerate 与 zip
java·前端·python
程序员agions5 小时前
Docker Compose 生产环境配置记录
运维·docker·容器
郝学胜-神的一滴5 小时前
Effective Python 条款45:巧用属性注解平滑升级类属性
运维·开发语言·数据库·python·网络协议·numpy