-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpknucroller.py
66 lines (41 loc) · 1.32 KB
/
pknucroller.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
60
61
62
63
64
import requests
import ssl
from bs4 import BeautifulSoup
import os
import json
url = "https://ce.pknu.ac.kr/ce/1814"
req = requests.get(url, verify=False)
html = req.text
soup = BeautifulSoup(html, 'html.parser')
my_titles = soup.select(
'#sbCont > div > table > tbody > tr > td.bdlTitle > a'
)
new_data = {}
for title in my_titles :
new_data[title.text] = title.get('href')
#저장되어 있던 이전 정보
# 만약 새로운 정보가 추가되어다면
updated_data = {}
with open('/Users/yoon/vscode/PKNUCrolling/result.json', 'r') as file:
prev_datas = json.load(file)
keys = new_data.keys() - prev_datas.keys()
if len(keys) == 0:
for i in range(3):
print()
print("업데이트 사항 없음")
for i in range(3):
print()
else :
for i in range(3):
print()
for key in keys:
print(url + new_data[key])
for i in range(3):
print()
# 1. 새로운 정보 (타이틀, href) 리턴
# 2. json file 에 해당 정보 추가.
# 만약 없다면 그냥 끝내기
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# json 파일에 새로운 정보 저장하기 .
with open(os.path.join(BASE_DIR, 'result.json'), 'w+') as json_file:
json.dump(new_data, json_file)