自动化刷题小练习

驾校题库自动化刷题,使用了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)
相关推荐
Techblog of HaoWANG2 分钟前
具身智能机器人专题(4) Docker 实战
linux·运维·ubuntu·docker·容器·机器人·ollama
跨境猫小妹8 分钟前
自动化点不到页面按钮,先查元素定位还是渲染时机
运维·自动化·跨境电商·营销策略
天远API28 分钟前
零信任架构实战:基于天远单人婚姻查询构建自动化保障房准入审核网关
运维·人工智能·架构·自动化
墨痕诉清风1 小时前
docker无法pull镜像问题解决
运维·docker·容器
benchmark_cc1 小时前
一次获取多只股票实时行情:QuantDash `quotes.get(symbols=[...])` 批量快照
开发语言·python·数据分析·pandas·量化交易·股票数据·quantdash
geovindu1 小时前
python: PCA
开发语言·后端·python·算法
DeskUI~~2 小时前
8.4M,我把 Linux 变成了一块“磁盘”
linux·运维·服务器
无足鸟ICT2 小时前
【RHCA+】_proc_pid_environ
linux·运维·服务器
AI模型调用笔记2 小时前
流式 API 的 usage 为 null?用 cURL 看尾帧,别漏空 choices
python
天诰3 小时前
SA-T-06 轨迹数据工程 脏数据检测
人工智能·python·算法·语言模型·ai编程