-
카테고리
-
세부 분야
데이터 분석
-
해결 여부
해결됨
강의 크롤링 엑셀 파일로 저장하는 것까지 추가해 봤습니다.
24.04.23 23:04 작성 조회수 49
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()
답변을 작성해보세요.
1
답변 1