반응형
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 | 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.now() return 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 |
반응형
'프로젝트' 카테고리의 다른 글
보안뉴스 웹크롤링(9) 완료 (0) | 2020.08.11 |
---|---|
보안뉴스 웹크롤링(8) (0) | 2020.08.09 |
보안뉴스 웹크롤링(6) (0) | 2020.08.07 |
보안뉴스 웹크롤링(5) (0) | 2020.08.06 |