自动化刷题小练习

驾校题库自动化刷题,使用了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)
相关推荐
Tel199253080043 小时前
全新C-Components高压继电器P/N 500-214
单片机·物联网·自动化·工业自动化
张太行_4 小时前
Linux静态库:多模块高效管理
linux·运维·服务器
web3.08889994 小时前
微店商品详情API实用
python·json·时序数据库
知乎的哥廷根数学学派4 小时前
基于数据驱动的自适应正交小波基优化算法(Python)
开发语言·网络·人工智能·pytorch·python·深度学习·算法
sunfove4 小时前
将 Python 仿真工具部署并嵌入个人博客
开发语言·数据库·python
Learner4 小时前
Python类
开发语言·python
wgl6665204 小时前
Linux---基础IO!
linux·运维·服务器
2501_941329725 小时前
门及其组件定位识别_YOLO13-C3k2-PoolingFormer改进模型研究
python
Ancelin安心5 小时前
kali-dirsearch的使用
linux·运维·服务器·python·计算机网络·web安全·网络安全
努力学习的小洋5 小时前
Python训练打卡Day5离散特征的处理-独热编码
人工智能·python·机器学习