해결된 질문
작성
·
133
1
## 엑셀 시트 연습겸 추가했습니다.
## 좋은 강의 감사합니다.
import re
from bs4 import BeautifulSoup
import requests
import openpyxl
res = requests.get('https://davelee-fun.github.io/blog/crawling_stock_example.html')
soup = BeautifulSoup(res.content, 'html.parser')
items = soup.select('li.row_sty')
excel_file = openpyxl.Workbook()
excel_sheet = excel_file.active
excel_sheet.title = 'Sheet1'
excel_sheet.append(['회사명','주식 가격','변동율'])
for i in items:
a = i.select_one('div.st_name').get_text().replace(" ","").replace('\n','')
b = i.select_one('div.st_price').get_text().replace('\n','').replace(" ","")
c = i.select_one('div.st_rate').get_text().replace('\n','').replace(" ","")
excel_sheet.append([a,b,c])
excel_file.save('stock.xlsx')
excel_file.close()