import datetime
from bs4 import BeautifulSoup as bs
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.find_all("span",class_="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")
name_article_euc_kr = str(name_article_euc)
name_article_euc_kr = name_article_euc_kr.replace("\\x","%").replace("b","").replace("\'", "")
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