刷题查询


code: :记得用pythonpython打开,没有的去MicrosoftStore(3.12以上版本)Microsoft Store(3.12以上版本)下一个就可以了下的很快

###
# 使用说明
# https://acjudge.com/d/wfoj/user/UID
# 开始运行时UID输入你的UID
# 运行代码即可
# 如果失效接着往下看这篇博客(https://acjudge.com/blog/267/668a8a1551518a7be2b950e7)
# ###
import requests
import re
from lxml import etree

n=0
ans=0
def chaxun(n):
    n=int(input("你要查几名用户的做题情况?"))
    
    for i in range(n):
        print("-----------------------------------")
        id=input("UID:")
        urls=[
            "https://acjudge.com/d/wfoj/user/",
            "https://acjudge.com/d/beichenoi/user/",
            "https://acjudge.com/user/",
            "https://acjudge.com/d/Level1/user/",
            "https://acjudge.com/d/Level2/user/",
            "https://acjudge.com/d/Level3/user/",
            "https://acjudge.com/d/Level4/user/",
            "https://acjudge.com/d/Level5/user/",
            "https://acjudge.com/d/Level6/user/",
            "https://acjudge.com/d/atcoder/user/",
            "https://acjudge.com/d/codeforces/user/",
        ]
        na=['高新OI:','北辰OI:','主域:','Level1:','Level2:','Level3:','Level4:','Level5:','Level6:','Atcoder:','Codeforces:','总计:']

        user = {
            "Cookie":"sid=kvMs2wk9sir6Ha1MF9e4jNwGvUQAwjss; sid.sig=NZmib2nD1x6HysVaCbzI2GD_rTM",
            "User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
        }
        def put_c(id):
            sum = 0
            for i in range(len(urls)):
                url=urls[i]+id
                res = requests.get(url,headers=user)
                html = etree.HTML(res.content)
                name = html.xpath('//*[@id="panel"]/div[3]/div/div[1]/div/div[1]/div/div/div[2]/h1/text()')
                name = re.findall('[\u4e00-\u9fa5]',name[0])
                name = ''.join(name)
                c = html.xpath('//*[@id="panel"]/div[3]/div/div[1]/div/div[1]/div/div/div[2]/p[2]/text()')
                c = re.search('解决了(.*?\d+)',c[0]).group(1)
                sum +=int(c)
                print(name+"  "+na[i]+c)
                if i==len(urls)-1:
                    print(na[-1]+str(sum))

        if __name__ == '__main__':
            put_c(id)
        print("-----------------------------------")
    print("已查询完毕")
    
    def xunwen(ans):
        ans = input("如果再次查询请输入'YES' 输入:")
        if ans == "YES":
            chaxun(n)
        
        ans = 0
        
        while ans != "1":
            ans = input("关闭程序请按 1 ")
        
    xunwen(ans)


chaxun(n)


我猜有一群人会出错,在requests这个单词,提示是No module named 'requests',因为这是requestsrequestspythonpython第三方库,你没安装所以会报错,我们这是只需按下WIN+RWIN+R再写cmdcmd打开cmdcmd下一下requestsrequests,咋下呢?我们写

pip install requests

就可以了. 如果有错在了from lxml import etree这里我们可以再 按下WIN+RWIN+R再写cmdcmd打开cmdcmd写:

pip install lxml

就没有问题了 就可以查询你做了几道题了!