깃헙 액션
깃헙 액션(GitHub Action)은 깃헙에서 제공하는 CI/CD 서비스입니다. 깃헙 저장소에 푸시가 발생하면 깃헙 액션을 통해 빌드, 테스트, 배포 등의 작업을 자동화할 수 있다.
크로링
주식가격
네이버 금융 크롤링 파이썬 코드를 참고하여 챗GPT로 코드를 동작하는 코드를 생성한다.
코드
import requests
from bs4 import BeautifulSoup
def get_stock_info(stock_code):
= f"https://finance.naver.com/item/main.nhn?code={stock_code}"
url = requests.get(url)
response = BeautifulSoup(response.text, 'html.parser')
soup
# Attempt to extract the stock name with a more robust approach
= soup.find("div", {"class":"h_company"})
company_info = company_info.find("a").text
stock_name
# Find the element containing the current price
= soup.find("p", {"class": "no_today"})
current_price_container = current_price_container.find("span", {"class": "blind"}).get_text() if current_price_container else "Price not found"
current_price
return stock_name, current_price
# Example usage
= '005930' # Samsung Electronics code
stock_code = get_stock_info(stock_code)
stock_name, current_price print(f"{stock_name} (code {stock_code}) 현재가격: {current_price} KRW.")
삼성전자 (code 005930) 현재가격: 74,900 KRW.
R 코드로 변환
프롬프트: 다음 코드를 R 코드로 변환해줘
인코딩 이슈가 있어 read_html()
에서 다음과 같이 변환한다.
Warning: package 'rvest' was built under R version 4.3.3
코드
get_stock_info <- function(stock_code) {
url <- sprintf("https://finance.naver.com/item/main.nhn?code=%s", stock_code)
webpage <- read_html(url, encoding = "euc-kr") # Setting the encoding to EUC-KR
# Attempt to extract the stock name with a more robust approach
company_info <- html_node(webpage, "div.h_company")
stock_name <- html_text(html_node(company_info, "a"))
# Find the element containing the current price
current_price_container <- html_node(webpage, "p.no_today")
if (!is.null(current_price_container)) {
current_price <- html_text(html_node(current_price_container, "span.blind"))
} else {
current_price <- "Price not found"
}
list(stock_name = stock_name, current_price = current_price)
}
# Example usage
stock_code <- '005930' # Samsung Electronics code
info <- get_stock_info(stock_code)
cat(sprintf("%s (code %s) 현재가격: %s KRW.\n", info$stock_name, stock_code, info$current_price))
삼성전자 (code 005930) 현재가격: 74,900 KRW.