[Python] 역대 로또 당첨 번호 CSV 파일로 저장

Programming|2020. 12. 10. 11:54
728x90
반응형

from urllib.request import urlopen
import pandas as pd
import json

for i in range(1, 1000):

url="https://www.dhlottery.co.kr/common.do?method=getLottoNumber&drwNo="+str(i)

result_data = urlopen(url)
result = result_data.read()

lotto = json.loads(result)

lotto_num = ({str(lotto["drwNo"])+','+str(lotto["drwNoDate"])+','+str(lotto["totSellamnt"])+','+str(lotto["firstAccumamnt"])+','+str(lotto["firstPrzwnerCo"])+','+str(lotto["firstWinamnt"])+','+str(lotto["drwtNo1"])+','+str(lotto["drwtNo2"])+','+str(lotto["drwtNo3"])+','+str(lotto["drwtNo4"])+','+str(lotto["drwtNo5"])+','+str(lotto["drwtNo6"])+','+str(lotto["bnusNo"])})
print(lotto_num)

db = pd.DataFrame(lotto_num)
db.to_csv("lotto_number_history.csv", header=False, mode='a')

반응형

댓글()