-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoticeCSE.py
36 lines (29 loc) · 1.06 KB
/
noticeCSE.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
import requests
from bs4 import BeautifulSoup
def get_CSE_notice():
#학과 공지사항 파싱
url = 'https://cse.pusan.ac.kr/cse/14651/subview.do'
response = requests.get(url)
notice_data = []
if response.status_code == 200:
html = response.text
soup = BeautifulSoup(html, 'html.parser')
tr = soup.find_all('tr')
# 중요공지 1개와 최근 공지사항 처리
filtered_rows = [tr[1]]
for row in tr:
td_num = row.find('td', class_='_artclTdNum')
if td_num and not td_num.find('span', class_='_artclNotice _artclNnotice'):
filtered_rows.append(row)
#필터링된 공지사항 처리
for content in filtered_rows:
notice = {
"title" : content.find('strong').get_text(),
"new" : bool(content.find(class_='newArtcl'))
}
notice_data.append(notice)
else:
print(f'Error: {response.status_code}')
return notice_data
if __name__ == '__main__':
print(get_CSE_notice())