CSB261 commited on
Commit
86797a6
1 Parent(s): 92eff32

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ from bs4 import BeautifulSoup
3
+ import pandas as pd
4
+
5
+ # URL 설정
6
+ url = "https://news.naver.com/main/ranking/popularDay.naver"
7
+
8
+ # 요청 보내기
9
+ response = requests.get(url)
10
+ soup = BeautifulSoup(response.content, 'html.parser')
11
+
12
+ # 뉴스 리스트 추출
13
+ news_list = []
14
+
15
+ for news_item in soup.select('div.rankingnews_box ul.rankingnews_list li'):
16
+ rank = news_item.find('em', class_='list_ranking_num').text
17
+ title = news_item.find('a', class_='list_title').text.strip()
18
+ link = news_item.find('a', class_='list_title')['href']
19
+ time = news_item.find('span', class_='list_time').text.strip()
20
+ image_url = news_item.find('img')['src']
21
+
22
+ news_list.append({
23
+ 'Rank': rank,
24
+ 'Title': title,
25
+ 'Link': link,
26
+ 'Time': time,
27
+ 'Image URL': image_url
28
+ })
29
+
30
+ # 데이터프레임으로 변환
31
+ df = pd.DataFrame(news_list)
32
+
33
+ # 결과 출력
34
+ print(df)