import requests
from bs4 import BeautifulSoup
import openpyxl
fpath = r"C:\Users\OWNER\Desktop\python\주식.xlsx"
wb = openpyxl.load_workbook(fpath)
ws = wb.active
codes = [
'005930',
'000660',
'035720'
]
row = 2
for code in codes :
url = f"https://finance.naver.com/item/sise.naver?code={codes}"
response = requests.get(url)
html = response.text
soup = BeautifulSoup(html,'html.parser')
price = soup.select_one('#_nowVal').text
price = price.replace(',', '')
print(price)
wb.save(fpath)
값이 빈어서 출력이 됩니다...