首页 > 其他分享 >5.30博客

5.30博客

时间:2024-06-16 20:21:32浏览次数:8  
标签:count plt 博客 break 5.30 year print select

周三:python和工程数学

python学习:

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 = 2015

for i in range(15, 20):

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 = 2019 - 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

标签:count,plt,博客,break,5.30,year,print,select
From: https://www.cnblogs.com/zjm921/p/18251188

相关文章

  • 5.14博客
    学习内容:安卓<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"  xmlns:tools="http://schemas.android.com/tools"  android:layout_width="match_parent"  android:layout_height="wrap_content"......
  • 5.13博客
    看看日历又是周一,本来都起床了感觉尸体有点不舒服,再躺会吧学习内容:安卓<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="......
  • 5.17博客
    排球课比赛快完了,目前为止一场没输过,我感觉这跟我课脱不了关系学习内容:spring-boot注册条件安卓:<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"  xmlns:tools="http://schemas.android.com/tools"  android:id="@+id/ll_item"  an......
  • 5.6博客
    过完五一假了该进入学习状态了学习内容:安卓<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"  xmlns:tools="http://schemas.android.com/tools"  android:layout_width="match_parent"  android:layout_height="m......
  • 4.30博客
    上午计网下午建民课晚上跑步真是充实学习内容:安卓<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical&qu......
  • 2024年6月16日 18:10,cnblog博客园的第一天!!!
    终于A了P06614迷宫游戏5,原来是动态规划......点击查看代码#include<bits/stdc++.h>#definedebug(a);cout<<#a<<"="<<a<<endl;#definerep(i,a,b)for(inti=a;i<=b;i++)#definepep(i,a,b)for(inti=a;i>=b;i--)usingnamespacestd;......
  • css样式综合案例----博客园首页简单搭建
    1<!DOCTYPEhtml>2<htmllang="en">3<head>4<metacharset="UTF-8">5<title>博客园</title>6<metaname="viewport"content="width=device-width,initial-scal......
  • 博客园入门
    一、语言:通常博客都是采用markdown语言。1.1markdown语言教程1:https://markdown.com.cn/basic-syntax/教程2:https://forum-zh.obsidian.md/t/topic/435/教程3:https://markdown.com.cn/intro.html1.2Html语言(1)markdown提供了可无缝转换为HTML的轻量级语法。对于......
  • 5.30
    今日总结学习时间很久请看代码packagecom.app.chapter03;importstaticcom.app.chapter03.R.*;importandroid.os.Bundle;importandroid.widget.TextView;importandroidx.activity.EdgeToEdge;importandroidx.appcompat.app.AppCompatActivity;importandroidx.core.graph......
  • 博客园商业化之路-众包平台:继续召集早期合作开发者
    会员、周边、广告是园子现在维持生存的主要收入来源,而众包平台是园子未来实现商业化规模增长的希望所在。今年5月开始的众包平台建设是万里长征,不仅需要融资,还需要找到合伙人组建新的团队。虽然当前既没有钱又没人,但万里长征已经迈出了第一步,采用企业微信+自己搭建的gitlab以原......