-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
59 lines (43 loc) · 1.62 KB
/
main.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from bs4 import BeautifulSoup
import urllib.request
import requests
# import os // now useless
def get_info(name):
url = 'https://www.acmicpc.net/user/' + name
# infomation of browser
user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36'
hds = { 'User-Agent' : user_agent }
req = urllib.request.Request(url, headers = hds)
temp = 0
fp = None
while temp < 10:
try:
fp = urllib.request.urlopen(req, timeout = 10)
break
except:
temp += 1
if fp == None:
print(name+'이라는 유저는 없어요!')
return 0
source = fp.read()
fp.close()
soup = BeautifulSoup(source, 'html.parser')
tbody = soup.find('tbody')
items = tbody.find_all('tr')
print(name+'님의 정보입니다.')
for i in items:
key = i.find('th').get_text(strip = True)
tmp = i.find('td').get_text().split()
val = ', '.join(tmp)
print(key + ': ' + val)
if __name__ == '__main__':
name = input('누구의 정보를 읽어올까요?\n\
만약 여러 명의 정보를 원하면 쉼표를 이용해 입력해주세요!\n: ')
name = name.replace(" ","") # no whitespaces
name = name.split(',') # split by comma
for names in name:
if names != '': # except ''
get_info(names)
print('') # new line
#os.system('pause')
input('종료하려면 아무 키나 누르십시오...') # 쉘에서 cmd창 안뜨게