Created
April 14, 2015 08:39
-
-
Save Baekjoon/6529ebc40a9c3d8aa21a to your computer and use it in GitHub Desktop.
acmicpc-ranklist-json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib | |
import json | |
from bs4 import BeautifulSoup | |
fp = urllib.urlopen('https://www.acmicpc.net/ranklist') | |
source = fp.read() | |
fp.close() | |
soup = BeautifulSoup(source) | |
table = soup.find(id="ranklist") | |
trs = table.tbody.find_all('tr') | |
ans = [] | |
for tr in trs: | |
tds = tr.find_all('td') | |
rank = int(tds[0].string.strip()) | |
user_id = tds[1].a.span.string.strip() | |
quote = tds[2].string.strip() | |
solved = int(tds[3].a.string.strip()) | |
submit = int(tds[4].a.string.strip()) | |
ans.append({rank:rank, user_id: user_id, | |
quote:quote, solved:solved, submit: submit}) | |
with open('ranklist.json','w') as fp: | |
fp.write(json.dumps(ans)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment