Python 获取Vjudge用户AC题数
Description
根据用户名,统计Vjudge某些用户AC题数目
Code
import bs4
import requests
from bs4 import BeautifulSoup
def getText(url):
try:
r = requests.get(url)
r.raise_for_status()
r.encoding = r.apparent_encoding
return r.text
except:
return ""
def solve(html):
soup = BeautifulSoup(html, "html.parser")
for tr in soup.find('table').children:
if isinstance(tr, bs4.element.Tag):
th = tr.find("th")
if th.string == "Overall solved":
a = tr.find('a')
print(a.string)
break
users = [ 'A_Wanderer', '2017RenYaochen', '2017liuyidi', 'Create_miracles', 'ltrbless',
'The__Flash', 'lanzongwei', '18wangxin', '2018muyu', 'tianjian2017',
'shenmafuyun', 'xiaobian', 'Moon1129', 'ignb', '18XiWenjuan', 'gw76999',
'2018SongYihao', '18yanmingfu', '18qinpeng', '2018fenggen', 'Thankyou' ]
def main():
url = "https://vjudge.net/user/"
# username = input()
for username in users:
url = "https://vjudge.net/user/"
url += username
html = getText(url)
print(username, end=' : ')
solve(html)
if __name__ == "__main__":
main()