상세 컨텐츠

본문 제목

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()

 

 

 

반응형

ai 핫토픽

챗GPT 무료 와 챗GPT 유료 차이점과 GPT-4 무료 사용법

챗GPT 어플, 안드로이드 앱 설치와 사용법, GPT-4o 음성 대화, 무료 사용법

GPT-5와 의료 분야, AI의 역할 재정립

경제 지표 시계열 분석을 통한 정책 제언, 파이썬을 활용한 GDP 성장률 예측과 그 활용법

챗GPT 한국어 설정, 챗GPT 한글 사용법


챗GPT 무료로 사진같은 그림 그리기


관련글 더보기