侧边栏壁纸

广西一键青年大学习升级版

2023年11月05日 563阅读 0评论 0点赞

废话少说,上代码

code1.png

# -*- coding: utf-8 -*-
"""
# @FilePath     : qndxx\\gx\\mian.py
# @creationTime : 2023-10-27 00:38:57
# @Author          : 魔法师
# @E-mail          : 2782226338@qq.com
# @BlogLink     : bytesquadblog.cn
# @Motto        : No sailor skilled was ever made By sailing on a sea of jade.
# @Description:
    1、可以写入数据,删除数据
    2、可以是单人学习,也可以是多人学习
    3、直接运行Python代码,不用做太多操作
    4、很好的保护隐私,大学习信息不外露
    5、官方接口,不怕信息泄露 
    6、需要安装的库很少 
        在终端输入以下命令
        pip install prettytable
        pip install  DrissionPage
        pip install prettytable
        pip install DrissionPage --upgrade

"""
import sqlite3,os
from DrissionPage import ChromiumPage
from urllib.parse import quote,unquote
import prettytable
# 数据库
dbdase = 'le.db'
# 是否需要输入输入框输入信息
_inoput = False
# 是否删掉数据
delete_dase = True
# 写入数据
is_write = False
# 查看信息
_inquire = True

# ---------------------------start-------------------
# 如果没有数据库文件,则创建数据库
if not os.path.exists(dbdase):
    # 连接数据库
    conn = sqlite3.connect(dbdase)
    cur =conn.cursor()
    # 创建表头
    cur.execute("""CREATE TABLE study (
                name TEXT,
                learning_id integer
    );""")

    _name = input('>>>请输入大学习昵称:')
    learning_id = input('>>>请输入学习编号:')
    name = quote(_name)
    cur.execute("INSERT INTO study (name, learning_id) VALUES (?, ?)", (name, learning_id))
    conn.commit()
    conn.close()
    print('写入数据成功!')

# 如果需要再写入数据,则显示提示框
elif _inoput:
        conn = sqlite3.connect(dbdase)
        cur = conn.cursor()
        _name = input('>>>请输入大学习昵称:')
        learning_id = input('>>>请输入学习编号:')
        name = quote(_name)
        cur.execute("INSERT INTO study (name, learning_id) VALUES (?, ?)", (name, learning_id))
        conn.commit()
        conn.close()
        print('写入数据成功!')
# 写入班级信息        
while is_write:
     conn = sqlite3.connect(dbdase)
     cur = conn.cursor()
     _name = input('>>>请输入大学习昵称(按q结束写入):')
     if _name.strip() == 'q':
          is_write = False
          quit()
     else:
        learning_id = input('>>>请输入学习编号:')
        name = quote(_name)
        cur.execute("INSERT INTO study (name, learning_id) VALUES (?, ?)", (name, learning_id))
        conn.commit()
        conn.close()
        print('写入数据成功!')
#-------------------- end -------------------------     

# // 完成写入信息start--------------------------------
con = sqlite3.connect(dbdase)
cur = con.cursor()
cur.execute("SELECT name,learning_id FROM study;")
_data = []
for row in cur.fetchall():
    _data.append(row)


# // 完成写入信息end----------------------------------------

# --------------start 删除个人信息---------------------------
def delete_(num,bool):
     
     conn = sqlite3.connect(dbdase)
     cur = conn.cursor()
     if bool:
          if num == 0:
               cur.execute("DELETE FROM study")
          elif num == 1:
               na = input(">>>你要删除谁的数据?")
               name = quote(na)
               cur.execute("DELETE FROM study WHERE name = ?;", (name,))
               print(name,'it is delete!')
     conn.commit()
     conn.close()

# 删除数据or删除某项数据,1 是删除某个同学的信息,0是全部删除
delete_(0,delete_dase)

#---------------------删除信息end-----------------------------------
# quit()

# 查看数据库里有谁----------------------start------------------------
if _inquire:
    table = prettytable.PrettyTable()
    table.field_names = ['姓名','编号']

    conn = sqlite3.connect(dbdase)
    cur  = conn.cursor()
    cur.execute("SELECT * FROM study;")
    for row in cur.fetchall():
        rq = unquote(row[0])
        table.add_row((rq,row[1]))
    print(table)
    cur.close()
    
    quit()
     

# -------------------------end--------------------------
if _inquire:
     pass

for data in _data:
    page = ChromiumPage()
    page.set.load_strategy.eager()
    page.get('http://qndxx.bestcood.com/nanning/daxuexi')
    # 模拟点击操作
    # 尝试点击退出登录,如果有退出登录 】

    try:
        page.ele('.sign-out').click()
    except:
        pass
    # 输入名字
    page.ele('#userName').input(unquote(data[0]))
    # 输入编号
    page.ele('#userId').input(data[1])
    # 点击登录
    page.ele('#btn-login').click()
    # 等待加载
    page.wait.load_start()

    bd = page('.bd').text
    # 点击开始学习
    page.ele('#btn-learn-start').click()
    # 尝试以下操作
    try:
        el = page('tag:select')
        # 选择广西
        el.select.by_index(21)
        page.wait.load_complete()
        # 选择南宁
        el = page('#city')
        el.select.by_text(text='南宁市')
        # 点击确定
        page.ele('.sure').click()

        page.wait.load_complete()
        # 点击开始查看
        page.ele('.start_btn on').click()
        page.wait.load_complete()
        # 观看完毕,返回首页
        page.get('http://qndxx.bestcood.com/nanning/daxuexi')
    except:
            page.wait.load_complete()
        # 点击开始查看
            page.ele('.start_btn on').click()
            # 返回到首页
            page.get('http://qndxx.bestcood.com/nanning/daxuexi')
    h1 = page.ele('tag:h1').text
    print(unquote(data[0]),h1,bd,'完成!!')
0

—— 评论区 ——

博主关闭了当前页面的评论