自动化刷题小练习

驾校题库自动化刷题,使用了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)
相关推荐
Flash.kkl3 小时前
Linux——进程信号
运维·服务器
苏宸啊4 小时前
Linux权限
linux·运维·服务器
多米Domi0114 小时前
0x3f第33天复习 (16;45-18:00)
数据结构·python·算法·leetcode·链表
Gofarlic_oms14 小时前
Windchill用户登录与模块访问失败问题排查与许可证诊断
大数据·运维·网络·数据库·人工智能
freepopo5 小时前
天津商业空间设计:材质肌理里的温度与质感[特殊字符]
python·材质
森叶5 小时前
Java 比 Python 高性能的原因:重点在高并发方面
java·开发语言·python
xqhoj5 小时前
Linux——make、makefile
linux·运维·服务器
文亭湖畔程序猿5 小时前
Debian 12 日常命令 & nano 快捷键速查表
运维·debian
张童瑶5 小时前
Linux 在线安装编译Python3.11
linux·运维·python3.11
ziqibit5 小时前
debian Live with Persistence 持久化U盘的debian系统
运维·debian