상세 컨텐츠

본문 제목

import matplotlib.pyplot as plt

시사경제지식

by 브로마리 2023. 8. 28. 13:50

본문

반응형

 

 

 

import requests
from bs4 import BeautifulSoup
from wordcloud import WordCloud
import matplotlib.pyplot as plt

# Daum 뉴스 페이지 URL
url = 'https://news.daum.net/'

# HTTP GET 요청을 보내고 페이지 내용 가져오기
response = requests.get(url)
html = response.text

# BeautifulSoup을 사용하여 HTML 파싱
soup = BeautifulSoup(html, 'html.parser')

# 뉴스 제목 추출
titles = []
headline_articles = soup.find_all("div", class_="item_issue")
for article in headline_articles:
    title = article.get_text(strip=True)
    titles.append(title)

# 워드클라우드 생성
text = ' '.join(titles)  # 모든 제목을 하나의 텍스트로 결합
wordcloud = WordCloud(
    width=800,
    height=400,
    background_color='white',
).generate(text)

# 워드클라우드 출력
plt.figure(figsize=(10, 5))
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis('off')
plt.show()

 

 

 

 

import requests
from bs4 import BeautifulSoup
from wordcloud import WordCloud
import matplotlib.pyplot as plt

# Daum 뉴스 페이지 URL
url = 'https://news.daum.net/'

# HTTP GET 요청을 보내고 페이지 내용 가져오기
response = requests.get(url)
html = response.text

# BeautifulSoup을 사용하여 HTML 파싱
soup = BeautifulSoup(html, 'html.parser')

# 뉴스 제목 추출
titles = []
headline_articles = soup.find_all("div", class_="item_issue")
for article in headline_articles:
    title = article.get_text(strip=True)
    titles.append(title)

# 워드클라우드 생성
text = ' '.join(titles)  # 모든 제목을 하나의 텍스트로 결합
wordcloud = WordCloud(
    width=800,
    height=400,
    background_color='white',
).generate(text)

# 워드클라우드 출력
plt.figure(figsize=(10, 5))
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis('off')
plt.show()

 

 

 

반응형

궁금할 만한 핫토픽 모음

아이폰16 Pro, 자급제, 사전 예약, 네이버 쇼핑 top 50




김포 재개발 대장주 한강 수자인 오브센트




챗GPT GPT-4o 무료로 그림 그리기



관련글 더보기