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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | import pandas as pd import datetime from bs4 import BeautifulSoup as bs from urllib.request import urlparse import urllib.request as req import urllib def Main_Menu() : print() print("--------메뉴선택--------") print("\t1. 오늘의 주요 기사는?") print("\t2. 주간의 인기 뉴스") print("\t3. 기사 검색하기") print("\t0. 종료하기") print("----------------------") def Today_Main_Post() : today = datetime.datetime.today() today_date = today.strftime("%Y-%m\\%d.") today_date = str(today_date).replace("-","년").replace("\\","월").replace(".","일") dates= [] titles=[] url = "https://www.boannews.com/media/t_list.asp" res = req.urlopen(url) soup = bs( res , "html.parser" ) today_main_posts_title = soup.select(" div.news_list > a > span.news_txt") today_main_posts_dates = soup.select(" div.news_list > span.news_writer") tmp = today_main_posts_dates for ls in tmp : today_main_posts_dates = ls.string dates.append(today_main_posts_dates.split("|")[1]) tmp = today_main_posts_title for ls in tmp : today_main_posts_title = ls.string titles.append(today_main_posts_title) i = 0 for ls in dates : dates[i] = dates[i].replace(" ","") i += 1 i = 0 boolean = True while boolean : if str(dates[i][0:11]) == today_date : print("#%d >>"%(i+1),titles[i]) else : boolean = False i += 1 def Week_Hit_News() : url = "https://www.boannews.com/media/o_list.asp" res = req.urlopen(url) soup = bs(res,"html.parser") Hit_News_List = soup.select("#main_HitNews > ul > li > a ") i = 1 for ls in Hit_News_List : Hit_List = ls.string print("#%d >>"%i,Hit_List) i+=1 def Search_Article(name_article) : name_article_euc = name_article.encode("euc-kr") #print(name_article_euc) name_article_euc_kr = str(name_article_euc) name_article_euc_kr = name_article_euc_kr.replace("\\x","%").replace("b","").replace("\'", "") #print(name_article_euc_kr) name_article_euc = urllib.parse.quote(name_article_euc) url = "https://www.boannews.com/search/news_list.asp?search=key_word&find="+name_article_euc res = req.urlopen(url) soup = bs(res,"html.parser") searching_news_title = soup.select("#news_area > div > a") i = 1 for ls in searching_news_title : News_title = ls.string if i >10 : continue elif News_title == None : continue else : print("#%d >>"%i,News_title) i+=1 while True : Main_Menu() menu_num = input("입력 : ") input_article = "" if int(menu_num) == 1 : Today_Main_Post() elif int(menu_num) == 2 : Week_Hit_News() elif int(menu_num) == 3: input_article = input("찾을 기사 제목 : ") Search_Article(input_article) elif int(menu_num) == 0 : break | cs |
'프로젝트' 카테고리의 다른 글
코틀린 안드로이드 가계부앱 - 1 (0) | 2024.12.13 |
---|---|
보안뉴스 웹크롤링(9) 완료 (0) | 2020.08.11 |
보안뉴스 웹크롤링(7) (0) | 2020.08.08 |
보안뉴스 웹크롤링(6) (0) | 2020.08.07 |