Python/Python-Lotto

Lotto 자동생성기 - 기존 당첨번호 가져오기

오마로 2024. 3. 14. 00:52
반응형

Lotto 기존 당첨번호 가져오기

1.Crawling
 1)로또 관련 주소

lotto_url = "https://www.dhlottery.co.kr/gameResult.do?method=byWin"                              # 마지막 회차를 얻기 위한 주소
lotto_game_url = "https://www.dhlottery.co.kr/gameResult.do?method=byWin&drwNo="    # 임의의 회차를 얻기 위한 주소

2)자료가져오기

import pandas as pd
import requests
from bs4 import BeautifulSoup

#로또 1회부터 N차까지 자료를 cvs에 저장하기

lotto_url = "https://www.dhlottery.co.kr/gameResult.do?method=byWin"                # 마지막 회차를 얻기 위한 주소
lotto_game_url = "https://www.dhlottery.co.kr/gameResult.do?method=byWin&drwNo="    # 임의의 회차를 얻기 위한 주소

# 마지막 회차 정보를 가져옴
def GetLast():
    resp = requests.get(lotto_url)
    soup = BeautifulSoup(resp.text, "lxml")
    result = str(soup.find("meta", {"id" : "desc", "name" : "description"})['content'])
    s_idx = result.find(" ")
    e_idx = result.find("회")
    return int(result[s_idx + 1 : e_idx])

# 지정된 파일에 지정된 범위의 회차 정보를 기록함
def Crawler(s_count, e_count, fp):
    for i in range(s_count , e_count + 1):
        crawler_url = lotto_game_url + str(i)
        resp = requests.get(crawler_url)
        soup = BeautifulSoup(resp.text, "html.parser")

        text = soup.text

        s_idx = text.find(" 당첨결과")
        s_idx = text.find("당첨번호", s_idx) + 4
        e_idx = text.find("보너스", s_idx)
        numbers = text[s_idx:e_idx].strip().split()

        s_idx = e_idx + 3
        e_idx = s_idx + 3
        bonus = text[s_idx:e_idx].strip()

        s_idx = text.find("1등", e_idx) + 2
        e_idx = text.find("원", s_idx) + 1
        e_idx = text.find("원", e_idx)
        money1 = text[s_idx:e_idx].strip().replace(',','').split()[2]

        s_idx = text.find("2등", e_idx) + 2
        e_idx = text.find("원", s_idx) + 1
        e_idx = text.find("원", e_idx)
        money2 = text[s_idx:e_idx].strip().replace(',','').split()[2]

        s_idx = text.find("3등", e_idx) + 2
        e_idx = text.find("원", s_idx) + 1
        e_idx = text.find("원", e_idx)
        money3 = text[s_idx:e_idx].strip().replace(',','').split()[2]

        s_idx = text.find("4등", e_idx) + 2
        e_idx = text.find("원", s_idx) + 1
        e_idx = text.find("원", e_idx)
        money4 = text[s_idx:e_idx].strip().replace(',','').split()[2]

        s_idx = text.find("5등", e_idx) + 2
        e_idx = text.find("원", s_idx) + 1
        e_idx = text.find("원", e_idx)
        money5 = text[s_idx:e_idx].strip().replace(',','').split()[2]

        line = str(i) + ',' + numbers[0] + ',' + numbers[1] + ',' + numbers[2] + ',' + numbers[3] + ',' + numbers[4] + ',' + numbers[5] + ',' + bonus + ',' + money1 + ',' + money2 + ',' + money3 + ',' + money4 + ',' + money5
        print(line)
        line += '\n'
        fp.write(line)

last = GetLast() # 마지막 회차를 가져옴

fp = open('2020-1-25-keras_lstm_lotto_v1110_data.csv', 'w')
Crawler(1, last, fp) # 처음부터 마지막 회차까지 저장
fp.close()

3)Result
1,10,23,29,33,37,40,15,0,143934100, 5140500, 113400, 10000
..........
1107,6,14,30,31,40,41,29,2025625233,57639743,1407942,50000,5000
1108,7,19,26,37,39,44,27,1957990849,47590056,1415757,50000,5000
1109,10,12,13,19,33,40,2,1584352875,53440474,1341202,50000,5000
1110,3,7,11,20,22,41,24,1647392719,37229214,1202258,50000,5000

2020-1-25-keras_lstm_lotto_v1110_data.csv
0.07MB


출처 : https://tykimos.github.io/2020/01/25/keras_lstm_lotto_v895/

 

딥로또 895회

딥러닝 세미나를 하다보면 (특히 RNN이나 LSTM 등 시계열 예측 모델을 설명하다보면) 로또나 주식에 관해 질문을 많이 하십니다. 이와 관련된 질문에는 나름 원칙이 있거나 시계열적 특성이나 인

tykimos.github.io

 

반응형