728x90
반응형
from bs4 import BeautifulSoup
import numpy as np
res = requests.get(html_url)
soup = BeautifulSoup(res.text, 'html.parser')
kbo_data = [i.text for i in soup.select( "#cphContents_cphContents_cphContents_udpRecord >table td")]
lists = [0,1,3,4,5,6]
kbo_data = [value for idx, value in enumerate(kbo_data) if idx%12 in lists][:60]
kbo_ranks = np.array(kbo_data).reshape((10,6))
head = np.array(["순위","팀","승","무","패","승률"])
result = np.vstack([head,kbo_ranks])
with open("rank.txt","w",encoding="utf-8") as file:
file.write("=========================KBO 순위=========================\n")
for row in range(len(result)):
for col in range(result.shape[1]):
file.write(f"{result[row][col]:<5}\t")
file.write("\n")
with open("rank.txt",'r',encoding="utf-8") as file:
data = file.read()
print(data)
반응형
'하루코딩 > python 하루코딩' 카테고리의 다른 글
| [Python] 막대그래프와 도넛 그래프 (0) | 2024.12.17 |
|---|---|
| [Python & 데이터] 공공데이터 활용 (0) | 2024.12.15 |
| [python & 데이터]git hub 로그인 하기 (0) | 2024.12.12 |
| 관람정보 & 기사 크롤링 (0) | 2024.12.12 |
| [Python] 파일 입출력 (1) | 2024.12.06 |