5.26每日总结

发布时间 2023-05-26 22:03:48作者: 漏网鲨鱼
<%@ page import="san.Thesql" %>
<%@ page import="san.Pd_stu" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"

         pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
  <title>信息查询</title>
  <style type="text/css">
    html,body{
      width: 99%;
      height: 99%;
    }
    h1 {
      color: #333;
      text-align: center;
      margin-top: 50px;
    }

    table {
      margin-top: 20px;
      border-collapse: collapse;
      box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
      background-color: #fff;
    }

    th, td {
      padding: 20px;
      text-align: center;
      border: 1px solid #ddd;
      font-size: 17px;
    }

    th {
      background-color: #8b8989;
      color: #fff;
      font-size: 24px;
    }

    tr:nth-child(even) {
      background-color: #f2f2f2;
    }
    input{
      border: none;
      border-radius: 10px;
      height: 27px;
    }
    .submit{
      background-color: rgb( 21, 218, 218);
      color: aliceblue;
      height: 50px;
      width: 60%;
    }
    .submit:active{
      background-color: rgb(166, 172, 175);
    }
    a{
      text-decoration: none;
      font-size: 20px;
      color: #3bc9e2;
    }
    .content {
      height: calc(95% - 0px);
      overflow-y: scroll;
    }
  </style>
</head>
<%
  Thesql thesql=new Thesql();
  Pd_stu pdStu[] = thesql.show_stu();
  int student_num = pdStu.length;
%>
<body>
<div align="center"><h1>学生联系方式</h1></div>
<div align="center"><a href="add.jsp">添加学生</a></div>
 <table width="90%" align="center">
    <tr>
      <th height="25%" width="25%">工号</th>
      <th width="25%">姓名</th>
      <th width="25%">手机号码</th>
      <th width="25%">管理</th>
    </tr>
    <tr><td colspan="5">
      <div class="content">
        <table border="1" style="font-size:18px;width: 100%;height: 100% ;margin-top: 0px">
          <%for(int i=0;i<student_num;i++){%>
          <tr>
            <td height="10%" width="25%"><%=pdStu[i].id%></td>
            <td width="25%"><%=pdStu[i].name%></td>
            <td width="25%"><%=pdStu[i].phone%></td>
            <td width="25%" align="center"><a href="person_information.jsp?id_=<%=pdStu[i].id%>" style="margin-right: 20%">查看</a>
              <a href="#">删除</a></td>
          </tr>
          <%} %>
        </table>
      </div>
    </td></tr>


  </table>
<script type="text/javascript">
</script>
</body>
</html>
import requests
from bs4 import BeautifulSoup as bs
import pandas as pd
from matplotlib import pyplot as plt

def get_rank(url):
    count = 0
    rank = []
    headers = {
        "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36 Edg/101.0.1210.3"
    }
    resp = requests.get(url, headers=headers).content.decode()
    soup = bs(resp, "lxml")
    univname = soup.find_all('a', class_="name-cn")
    for i in univname:
        if count != 10:
            university = i.text.replace(" ", "")
            score = soup.select("#content-box > div.rk-table-box > table > tbody > tr:nth-child({}) > td:nth-child(5)"
                                .format(count + 1))[0].text.strip()
            rank.append([university, score])
        else:
            break
        count += 1
    return rank


total = []
u_year = 2018
for i in range(18, 22):
    url = "https://www.shanghairanking.cn/rankings/bcur/20{}11".format(i)
    print(url)
    title = ['学校名称', '总分']
    df = pd.DataFrame(get_rank(url), columns=title)
    total.append(df)
for i in total:
    plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签
    x = list(i["学校名称"])[::-1]
    y = list(i["总分"])[::-1]
    # 1.创建画布
    plt.figure(figsize=(20, 8), dpi=100)
    # 2.绘制图像
    plt.plot(x, y, label="大学排名")
    # 2.2 添加网格显示
    plt.grid(True, linestyle="--", alpha=0.5)
    # 2.3 添加描述信息
    plt.xlabel("大学名称")
    plt.ylabel("总分")
    plt.title(str(u_year) + "年软科中国最好大学排名Top10", fontsize=20)
    # 2.5 添加图例
    plt.legend(loc="best")
    # 3.图像显示
    plt.savefig(str(u_year)+".png")
    plt.show()

    u_year += 1

while True:
    info = input("请输入要查询的大学名称和年份:")
    count = 0
    university, year = info.split()
    year = int(year)
    judge = 2022 - year
    tmp = total[::-1]
    if 4 >= judge >= 0:
        name = list(total[judge - 1]["学校名称"])
        for j in name:
            if university == j:
                print(university + "在{0}年排名第{1}".format(year, count + 1))
                break
            count += 1
        if count ==10:
            print("很抱歉,没有该学校的排名记录!!!")
            print("请选择以下选项:")
            print("   1.继续查询")
            print("   2.结束查询")
            select = int(input(""))

            if select == 1:
                continue
            elif select == 2:
                break
        else:
            break
    else:
        print("很抱歉,没有该年份的排名记录!!!")
        print("请选择以下选项:")
        print("   1.继续查询")
        print("   2.结束查询")
        select = int(input(""))

        if select == 1:
            continue
        elif select == 2:
            break