自动化刷题小练习

驾校题库自动化刷题,使用了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)
相关推荐
山峰哥12 小时前
Python爬虫实战:从零构建高效数据采集系统
开发语言·数据库·爬虫·python·性能优化·架构
Full Stack Developme15 小时前
Linux 多种压缩格式,优缺点和适用场景
linux·运维·服务器
yBmZlQzJ19 小时前
财运到内网穿透域名解析技术机制与中立评估
运维·经验分享·docker·容器·1024程序员节
Jay_Franklin19 小时前
SRIM通过python计算dap
开发语言·python
Shanxun Liao19 小时前
Cenots 7.9 配置多台 SSH 互信登陆免密码
linux·运维·ssh
j_xxx404_19 小时前
Linux:第一个程序--进度条|区分回车与换行|行缓冲区|进度条代码两个版本|代码测试与优化
linux·运维·服务器
是一个Bug19 小时前
Java基础50道经典面试题(四)
java·windows·python
一点晖光19 小时前
jenkins优化记录
运维·jenkins
吴佳浩19 小时前
Python入门指南(七) - YOLO检测API进阶实战
人工智能·后端·python
liliangcsdn20 小时前
python下载并转存http文件链接的示例
开发语言·python