[문과생도 AI] 1주차 과제

‘네이버에서 엔비디아 주식 관련 뉴스 크롤링해줘’를 chat gpt에게 요청했고 아래와 같은 결과물을 얻었습니다.

근데 선생님 이 결과물을 어떻게 사용해서 뉴스사를 크롤링해서 분류할 수 있는지를 모르겠네요 ㅠㅠ 제가 지금 해온 결과물이 과제로 인정되는건 맞는건가요? 혼란스럽네요…

import requests

from bs4 import BeautifulSoup

import pandas as pd

# Define the URL for Naver news search for NVIDIA stock

url = "https://search.naver.com/search.naver?where=news&query=엔비디아+주식"

# Send a GET request to the URL

response = requests.get(url)

# Check if the request was successful

if response.status_code == 200:

# Parse the HTML content

soup = BeautifulSoup(response.text, 'html.parser')

# Extract news articles

articles = soup.select('.news .type01 > li')

# Create a list to store the extracted data

data = []

for article in articles:

title = article.select_one('._sp_each_title').get_text()

link = article.select_one('._sp_each_title')['href']

source = article.select_one('.txt_inline').get_text()

summary = article.select_one('.dsc_txt_wrap').get_text()

data.append({

'Title': title,

'Link': link,

'Source': source,

'Summary': summary

})

# Create a DataFrame

df = pd.DataFrame(data)

# Display the DataFrame

print(df)

# Save the DataFrame to a CSV file

df.to_csv('nvidia_stock_news.csv', index=False)

else:

print("Failed to retrieve data from Naver")


이 스크립트를 아래 방법으로 쓰라는데 어느 프로그램에 들어가야되지요?

#AI로 개발하기

1
2개의 답글

👉 이 게시글도 읽어보세요