自动化刷题小练习

驾校题库自动化刷题,使用了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)
相关推荐
明月_清风6 小时前
Python 装饰器前传:如果不懂“闭包”,你只是在复刻代码
后端·python
明月_清风6 小时前
打破“死亡环联”:深挖 Python 分代回收与垃圾回收(GC)机制
后端·python
ZhengEnCi1 天前
08c. 检索算法与策略-混合检索
后端·python·算法
爱吃橘子橙子柚子1 天前
3CPU性能排查总结(超详细)【Linux性能优化】
运维·cpu
明月_清风1 天前
Python 内存手术刀:sys.getrefcount 与引用计数的生死时速
后端·python
明月_清风1 天前
Python 消失的内存:为什么 list=[] 是新手最容易踩的“毒苹果”?
后端·python
Flittly2 天前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(3)TodoWrite (待办写入)
python·agent
千寻girling2 天前
一份不可多得的 《 Django 》 零基础入门教程
后端·python·面试
databook2 天前
探索视觉的边界:用 Manim 重现有趣的知觉错觉
python·动效
明月_清风2 天前
Python 性能微观世界:列表推导式 vs for 循环
后端·python