码迷,mamicode.com
首页 > 其他好文 > 详细

设计自己的大学排名

时间:2020-05-21 00:16:47      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:span   ISE   ret   技术   cep   col   排名   form   科研   

查询广东技术师范大学2018年最好大学排名以及科研质量。

import requests
from bs4 import BeautifulSoup
allUniv=[]
def getHTMLText(url):
    try:
        r=requests.get(url,timeout=30)
        r.raise_for_status()
        r.encoding = utf-8
        return r.text
    except:
        return ""
def fillUnivList(soup):
    data = soup.find_all(tr)
    for tr in data:
        ltd = tr.find_all(td)
        if len(ltd)==0:
            continue
        singleUniv = []
        for td in ltd:
            singleUniv.append(td.string)
        allUniv.append(singleUniv)
def printUnivList(num):
    a="广东"
    print("{1:^2}{2:{0}^10}{3:{0}^6}{4:{0}^4}{5:{0}^10}".format(chr(12288),"排名","学校名称","省市","总分","科研质量"))
    for i in range(num):
        u=allUniv[i]
        #print(u[1])
        if a in u:
            print("{1:^2}{2:{0}^10}{3:{0}^6}{4:{0}^8.1f}{5:{0}^10}".format(chr(12288),i+1,u[1],u[2],eval(u[3]),u[7]))
def main():
    url=http://www.zuihaodaxue.cn/zuihaodaxuepaiming2018.html
    html = getHTMLText(url)
    soup = BeautifulSoup(html,"html.parser")
    fillUnivList(soup)
    num=len(allUniv)
    printUnivList(num)
main()

 

 

技术图片

查询广东技术师范学院的科研质量

import requests
from bs4 import BeautifulSoup
allUniv=[]
def getHTMLText(url):
    try:
        r=requests.get(url,timeout=30)
        r.raise_for_status()
        r.encoding = utf-8
        return r.text
    except:
        return ""
def fillUnivList(soup):
    data = soup.find_all(tr)
    for tr in data:
        ltd = tr.find_all(td)
        if len(ltd)==0:
            continue
        singleUniv = []
        for td in ltd:
            singleUniv.append(td.string)
        allUniv.append(singleUniv)
def printUnivList(num):
    a="广东技术师范学院"
    print("{1:^2}{2:{0}^10}{3:{0}^6}{4:{0}^4}{5:{0}^10}".format(chr(12288),"排名","学校名称","省市","总分","科研质量"))
    for i in range(num):
        u=allUniv[i]
        #print(u[1])
        if a in u:
            print("{1:^2}{2:{0}^10}{3:{0}^6}{4:{0}^8.1f}{5:{0}^10}".format(chr(12288),i+1,u[1],u[2],eval(u[3]),u[7]))
def main():
    url=http://www.zuihaodaxue.cn/zuihaodaxuepaiming2018.html
    html = getHTMLText(url)
    soup = BeautifulSoup(html,"html.parser")
    fillUnivList(soup)
    num=len(allUniv)
    printUnivList(num)
main()

技术图片

设计自己的大学排名

标签:span   ISE   ret   技术   cep   col   排名   form   科研   

原文地址:https://www.cnblogs.com/hyocheong/p/12927208.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!