Spaces:
Sleeping
Sleeping
Update app.py
Browse files8 unmodified lines91011121314151643 unmodified lines6061626162636465666763646566676869707172697071727374757677787980818273747576777879808182838485868788899091928485868793949596978990919293949598999697989910010110210310410510010110210310410510610710810911010711111211311411511611711811912012123 unmodified lines1451461471371481491501516 unmodified lines15815916015016116216316411 unmodified lines17617717816817918018118211 unmodified lines1941951961861971981992008 unmodified linesimport requestsfrom bs4 import BeautifulSoupimport timeimport instaloaderfrom instaloader import Post
PATH = './checkpoint-18750/'SEQ_LEN = 12843 unmodified lines return predict_answer
def get_comments(news_url): # oid, aid 추출
list = news_url.split("/") oid = list[-2] aid = list[-1] if len(aid) > 10: aid = aid[:10] if ('naver' in news_url): # oid, aid 추출 list = news_url.split("/") oid = list[-2] aid = list[-1] if len(aid) > 10: aid = aid[:10] # API URL 구성 api_url = "https://apis.naver.com/commentBox/cbox/web_naver_list_jsonp.json" params = { "ticket": "news", "templateId": "default_society", "pool": "cbox5", "lang": "ko", "country": "KR", "objectId": f"news{oid},{aid}", "pageSize": 100, "indexSize": 10, "page": 1, "sort": "FAVORITE" # 'NEW'(최신순), 'FAVORITE'(순공감순) } # API URL 구성 api_url = "https://apis.naver.com/commentBox/cbox/web_naver_list_jsonp.json" params = { "ticket": "news", "templateId": "default_society", "pool": "cbox5", "lang": "ko", "country": "KR", "objectId": f"news{oid},{aid}", "pageSize": 100, "indexSize": 10, "page": 1, "sort": "FAVORITE" # 'NEW'(최신순), 'FAVORITE'(순공감순) } headers = { "User-Agent": "Mozilla/5.0", "Referer": news_url } headers = { "User-Agent": "Mozilla/5.0", "Referer": news_url } # API 호출 및 데이터 처리 response = requests.get(api_url, params=params, headers=headers) content = response.text.replace("_callback(", "").replace(");", "") json_data = json.loads(content) # API 호출 및 데이터 처리 response = requests.get(api_url, params=params, headers=headers) content = response.text.replace("_callback(", "").replace(");", "") json_data = json.loads(content)
response = requests.get(news_url) article_soup = BeautifulSoup(response.text, "html.parser") response = requests.get(news_url) article_soup = BeautifulSoup(response.text, "html.parser")
# 제목 추출 title = article_soup.select_one("#ct > div.media_end_head.go_trans > div.media_end_head_title > h2") if title is None: title = article_soup.select_one("#content > div.end_ct > div > h2") # 본문 추출 article = article_soup.select_one("#dic_area") if article is None: article = article_soup.select_one("#articeBody") # 제목 추출 title = article_soup.select_one("#ct > div.media_end_head.go_trans > div.media_end_head_title > h2") if title is None: title = article_soup.select_one("#content > div.end_ct > div > h2") # 본문 추출 article = article_soup.select_one("#dic_area") if article is None: article = article_soup.select_one("#articeBody") return title.text.strip(), article.text.strip(), processing_data(json_data['result']['commentList']) return title.text.strip(), article.text.strip(), processing_data(json_data['result']['commentList']) else if ('insta' in news_url): list = news_url.split('/') pid = list[-2] + list[-1] L = instaloader.Instaloader() post = Post.from_shortcode(L.context, pid)
return '', post.caption, post.comments
def processing_data(comments): comment_list = []23 unmodified lines title, content, comments = get_comments(url) # 결과 표시 st.subheader("기사 제목") st.subheader("제목") st.write(title) st.subheader("본문 내용")6 unmodified lines # 결과 표시 st.subheader("기사 제목") st.subheader("제목") st.write(title) st.subheader("본문 내용")11 unmodified lines title, content, comments = get_comments(url) # 결과 표시 st.subheader("기사 제목") st.subheader("제목") st.write(title) st.subheader("본문 내용")11 unmodified lines title, content, comments = get_comments(url) # 결과 표시 st.subheader("기사 제목") st.subheader("제목") st.write(title) st.subheader("본문 내용")app.py+58-47