Showing
2 changed files
with
40 additions
and
2 deletions
| ... | @@ -38,4 +38,8 @@ | ... | @@ -38,4 +38,8 @@ |
| 38 | 코드 추가) | 38 | 코드 추가) |
| 39 | 2) 시간대별로 (시작시간, 끝시간)을 입력하여 그 시간에 해당하는 기사를 출력해주는 함수 구현 | 39 | 2) 시간대별로 (시작시간, 끝시간)을 입력하여 그 시간에 해당하는 기사를 출력해주는 함수 구현 |
| 40 | 40 | ||
| 41 | - 가장 자주 많이 나온 단어 검색과 MATPLOTLIB을 활용한 시각적 표현 구현 예정 | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 41 | + 가장 자주 많이 나온 단어 검색과 MATPLOTLIB을 활용한 시각적 표현 구현 예정 | ||
| 42 | + | ||
| 43 | +* 6차 수정사항 | ||
| 44 | + | ||
| 45 | + konlpy를 활용한 명사 추출 및 단어 빈도수가 많으 순대로 사용자가 입력한 limit만큼 출력해주는 함수 구현 완료 | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -2,6 +2,8 @@ from selenium import webdriver | ... | @@ -2,6 +2,8 @@ from selenium import webdriver |
| 2 | from selenium.common import exceptions | 2 | from selenium.common import exceptions |
| 3 | from bs4 import BeautifulSoup | 3 | from bs4 import BeautifulSoup |
| 4 | from datetime import datetime, timedelta | 4 | from datetime import datetime, timedelta |
| 5 | +from konlpy.tag import Twitter | ||
| 6 | +from collections import Counter | ||
| 5 | import time | 7 | import time |
| 6 | 8 | ||
| 7 | 9 | ||
| ... | @@ -160,7 +162,27 @@ def search_by_time(c_List,startTime, endTime) : | ... | @@ -160,7 +162,27 @@ def search_by_time(c_List,startTime, endTime) : |
| 160 | result_List.append(item) | 162 | result_List.append(item) |
| 161 | 163 | ||
| 162 | return result_List | 164 | return result_List |
| 163 | - | 165 | + |
| 166 | +def printMostShowed(c_List,limit): | ||
| 167 | + temp = "" | ||
| 168 | + result = "" | ||
| 169 | + for item in c_List: | ||
| 170 | + temp = str(item['comment']) + " " | ||
| 171 | + result = result + temp | ||
| 172 | + | ||
| 173 | + sp = Twitter() | ||
| 174 | + | ||
| 175 | + nouns = sp.nouns(result) | ||
| 176 | + | ||
| 177 | + _cnt = Counter(nouns) | ||
| 178 | + | ||
| 179 | + tempList = [] | ||
| 180 | + repCnt = 0 | ||
| 181 | + | ||
| 182 | + for i,j in _cnt.most_common(limit): | ||
| 183 | + print(str(repCnt+1)+'. '+str(i)+" : "+str(j)) | ||
| 184 | + repCnt += 1 | ||
| 185 | + | ||
| 164 | def printResult(c_List): | 186 | def printResult(c_List): |
| 165 | for i in range(0,len(c_List)): | 187 | for i in range(0,len(c_List)): |
| 166 | print(c_List[i]) | 188 | print(c_List[i]) |
| ... | @@ -182,6 +204,7 @@ def main (): | ... | @@ -182,6 +204,7 @@ def main (): |
| 182 | print('comment_list를 가져오는 중.....') | 204 | print('comment_list를 가져오는 중.....') |
| 183 | cList = getData(_url) | 205 | cList = getData(_url) |
| 184 | refine_time(cList) | 206 | refine_time(cList) |
| 207 | + #printMostShowed(cList,10) | ||
| 185 | print('\n') | 208 | print('\n') |
| 186 | print('comment_list를 다 가져왔습니다!') | 209 | print('comment_list를 다 가져왔습니다!') |
| 187 | 210 | ||
| ... | @@ -190,6 +213,7 @@ def main (): | ... | @@ -190,6 +213,7 @@ def main (): |
| 190 | print('1.닉네임 기반 검색') | 213 | print('1.닉네임 기반 검색') |
| 191 | print('2.키워드 기반 검색') | 214 | print('2.키워드 기반 검색') |
| 192 | print('3.작성시간 기반 검색') | 215 | print('3.작성시간 기반 검색') |
| 216 | + print('4.자주 나타난 단어 출력') | ||
| 193 | menu = input('메뉴를 입력해주세요: ') | 217 | menu = input('메뉴를 입력해주세요: ') |
| 194 | 218 | ||
| 195 | if(menu == str(1)): | 219 | if(menu == str(1)): |
| ... | @@ -218,6 +242,16 @@ def main (): | ... | @@ -218,6 +242,16 @@ def main (): |
| 218 | 242 | ||
| 219 | _result = search_by_time(cList,startTime,endTime) | 243 | _result = search_by_time(cList,startTime,endTime) |
| 220 | printResult(_result) | 244 | printResult(_result) |
| 245 | + elif(menu == str(4)): | ||
| 246 | + print('***********************************') | ||
| 247 | + inputLimit = input('상위 몇 개 까지 보고 싶은지 입력하세요(1~20): ') | ||
| 248 | + while(True): | ||
| 249 | + if (int(inputLimit) <= 0 or int(inputLimit) > 20): | ||
| 250 | + inputLimit = input('상위 몇 개 까지 보고 싶은지 입력하세요(1~20): ') | ||
| 251 | + else: | ||
| 252 | + break | ||
| 253 | + | ||
| 254 | + printMostShowed(cList,int(inputLimit)) | ||
| 221 | else: | 255 | else: |
| 222 | print('잘못된 입력입니다') | 256 | print('잘못된 입력입니다') |
| 223 | continue | 257 | continue | ... | ... |
-
Please register or login to post a comment