-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathranking_user.py
36 lines (26 loc) · 996 Bytes
/
ranking_user.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import requests
from bs4 import BeautifulSoup
import user_solving_number
import random
import json
result = []
pagerange = random.sample(range(1, 551), 10)
for page in pagerange:
res = requests.get("https://www.acmicpc.net/ranklist/"+str(page))
soup = BeautifulSoup(res.content, 'html.parser')
user_id_list = soup.select('tr')
user_id_list.pop(0)
for user_id in user_id_list:
user_row = user_id.select('td')
ranking = user_row[0].getText()
user_id_string = user_row[1].getText()
print(ranking +" : "+ user_id_string)
one_user_solving_list = user_solving_number.crawling_user_num(user_id_string)
one_result = {}
one_result['user_id'] = user_id_string
one_result['rank'] = int(ranking)
one_result['solving_problem'] = one_user_solving_list
json_one = json.dumps(one_result)
result.append(json_one)
with open("ranker_data.json", "w") as outfile:
json.dump(result, outfile)