自动化刷题小练习

驾校题库自动化刷题,使用了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)
相关推荐
_Jimmy_7 小时前
Agent 溯源精度提升方案
人工智能·python·langchain
晚风吹长发7 小时前
Docker基础——Docker Network(网络详解)
linux·运维·网络·ubuntu·docker·容器
SamChan908 小时前
在Web应用中集成PDF多语言翻译功能:PDFTranslator API实战指南
前端·python·ai·pdf·yapi·机器翻译
天天进步20158 小时前
Python全栈项目--智能办公自动化系统
开发语言·python
阿三08128 小时前
跨境电商售后自动化分级标准:哪些能全自动、哪些半自动、哪些禁止自动化
大数据·人工智能·自动化
颜酱8 小时前
09 | 重构项目结构
人工智能·python·langchain
LedgerNinja9 小时前
WEEX API 自动化交易实践:下单、撤单、订单查询与状态闭环
运维·自动化
执笔画流年呀9 小时前
Linux搭建Java项目部署环境
java·linux·运维
kisloy9 小时前
【爬虫入门第8讲】Python爬虫反爬入门
开发语言·爬虫·python
Dory_Youth10 小时前
联想笔记本电脑失灵
运维·笔记·电脑