SDNUOJ 新生 AC题数统计
Description
用于统计SDNUOJ上某(些)用户AC题目数量
import csv
import requests
from bs4 import BeautifulSoup
def getText(url):
try:
headers = {'user-agent': 'Mozilla/5.0'}
r = requests.get(url, headers=headers)
r.raise_for_status()
r.encoding = r.apparent_encoding
return r.text
except:
return ""
def solve(html):
soup = BeautifulSoup(html, "html.parser")
soup = soup.find("div", style="float: left;")
soup = BeautifulSoup(str(soup), "html.parser")
soup = soup.find_all("span")
soup = BeautifulSoup(str(soup[2]), "html.parser")
soup = soup.find("a")
num.append(soup.string)
#print(soup.string)
name = ("张华伟", "熊淑娴", "李瑞琪", "连泰杰", "查程曦",
"孔浩冉", "隋龙宇", "徐李添", "许世豪", "杨煜琦","程恩浩",
"姬彬荃", "王祥男", "韩瑶瑶", "孙海燕", "王玉莹",
"黄琪瑶", "郭双", "侯宛辰", "付浩翔", "温芯彧", "张立坤",
"王政", "纪毅", "李亚君", "商累浩", "邓博", "王君宇",
"陈子龙", "王超", "马丽媛", "孔一帆", "马国华", "李荣奥",
"刘怡萱", "张继慧")
users = [ '2019zhanghuawei', "19xiongshuxian", "2019liruiqi", "2019liantaijie", "19zhachengxi",
"2019konghaoran", "19suilongyu", "19xulitian", "19xushihao", "19yangyuqi", "19chengenhao",
"2019jibinquan", "19wangxiangnan", "19hanyaoyao", "19sunhaiyan", "2019wangyuying",
"19huangqiyao", "19", "19houwanchen", "19fuhaoxiang", "19wenxinyu", "19zhanglikun",
"19WANGZHENG", "2019jiyi", "2019liyajun", "shangleihao2019", "2019dengbo", "2019wangjunyu",
"19chenzilong", "19Wangchao", "19maliyuan", "19kongyifan", "19maguohua", "Visiter",
"2019liuyixuan", "19zhangjihui"]
dic_users_num = {}
dic_name_both = {}
num = []
list_dic = []
def main():
url = "https://vjudge.net/user/"
# username = input()
for username in users:
url = "http://www.acmicpc.sdnu.edu.cn/user/info/"
url += username
html = getText(url)
#print(username, end=' : ')
solve(html)
for i, s in enumerate(users):
dic_users_num[s] = num[i]
with open("19AC_2019_10_20.csv", "w", newline='', encoding='utf-16') as csvfile:
csvwriter = csv.writer(csvfile, delimiter=',')
csvwriter.writerow(['姓名', 'OJ用户名', 'AC数'])
i = 0
for key, value in dic_users_num.items():
csvwriter.writerow([name[i], key, value])
print("第" + str(i) + "个用户完成")
i += 1
if __name__ == "__main__":
main()
结果
打开.csv文件后数据是依据’,’分割的,此时新建一个excel,选择“数据”->”导入”->”按,分割”,再加以排序