eunja511005 / AutoCoding

0 stars 0 forks source link

파이썬 이용해서 네이버 주식 현재가 가져 오기 #183

Open eunja511005 opened 7 months ago

eunja511005 commented 7 months ago
from bs4 import BeautifulSoup
import pyautogui
import requests

codes = [
    '133690',
    '068270'
]

for code in codes:
    url = f'https://finance.naver.com/item/sise.naver?code={code}'
    response = requests.get(url)
    html = response.text
    soup = BeautifulSoup(html, 'html.parser')
    price = soup.select_one('#_nowVal').text
    price = price.replace(',', '').strip()
    print(price)