커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
저는 감성 분석을 해서 작동이 안됩니다. google colab 에서요
undefined주차
북마크
성*진
댓글
1
추천
0
조회수
14
조회수
14
답변 완료

* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.

* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.



저는 감성 분석을 해서 작동이 안됩니다. google colab 에서요








from bs4 import BeautifulSoup

import requests

from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer


# 검색할 키워드

query = "samsung electronics"


# 네이버 뉴스 검색 결과 URL

url = f"https://search.naver.com/search.naver?query={query}&where=news&ie=utf8&sm=nws_hty"


# 뉴스 헤드라인을 저장할 리스트

headlines = []


# 네이버 뉴스 검색 결과 페이지에서 뉴스 헤드라인 스크래핑

for page in range(16): # 1페이지부터 5페이지까지 검색 결과 수집

    res = requests.get(f"{url}&start={page*10-9}")

    soup = BeautifulSoup(res.text, "html.parser")

    titles = soup.find_all("a", class_="_sp_each_title")

    for title in titles:

        headlines.append(title.text)


# VADER 분석기 생성

analyzer = SentimentIntensityAnalyzer()


# 뉴스 헤드라인 감성분석 수행

for headline in headlines:

    vs = analyzer.polarity_scores(headline)

    print(headline)

    print(f"Sentiment: {vs['compound']:.2f}")

    print("="*50)





취소
 공유
취소
댓글 0
댓글 알림
나의얼굴