-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNoticeCrawler.py
36 lines (29 loc) · 1.2 KB
/
NoticeCrawler.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
from collections import OrderedDict
# 글 번호, 글 제목
noticeTitleTag = '#board-wrap > div.board-list-wrap > table > tbody > tr'
baseUrl = 'https://www.koreatech.ac.kr/'
class NoticeCrawler :
def __init__(self, soup, noticeType):
self.soup = soup
self.noticeType = noticeType
self.Message = ''
self.postList = []
self.selector = None
def crawling(self) :
self.selector = self.soup.select(noticeTitleTag)
for i in self.selector :
#print(i)
post_num = i.find('td').text
post_title = i.find('span')['title']
post_link = baseUrl + str(i.find('a')['href'])
self.postList.append([post_link, post_num, post_title])
return self
def getAnswer(self) :
post = ':loud_sound: *[{}]를 가져왔습니다.*\n'.format(self.noticeType)
jsonData = OrderedDict()
jsonData['color'] = '#2398cf'
jsonData['blocks'] = []
for i in range(len(self.postList)) :
post += '<{}|{}>\n'.format(self.postList[i][0],self.postList[i][2])
jsonData['blocks'].append({'type' :'section','text' : {'type' :'mrkdwn','text' : post }})
return jsonData