[파이썬 실습] 1등 로또 번호 확인하기 - urllib, html, BeautifulSoup

파이썬 실습 '로또 사이트 연결'

로또 사이트와 연결해서 회차 번호를 가져와 볼께요
타자 게임은 반복문(while문)을 사용합니다.



*****
urllib : URL(Uniform Resource Locator)을 가져오기 위한 파이썬 모듈


*****

01. 모듈 불러오기

import urllib.request
import urllib.parse
from bs4 import BeautifulSoup


02. 입력한 로또 회차 URL 확인하기 (링크)

lotto_no = urllib.parse.quote_plus(input('로또 당첨번호 회차를 입력해주세요 :'))
win_result = int(lotto_no)
url = f'https://dhlottery.co.kr/gameResult.do?method=byWin&drwNo={win_result}'

html = urllib.request.urlopen(url).read()
soup = BeautifulSoup(html, 'html.parser')

print(url)


03. 입력한 로또 회차 당첨 번호 확인하기


lotto_no = urllib.parse.quote_plus(input('로또 당첨번호 회차를 입력해주세요:'))
win_result = int(lotto_no)
url = f'https://dhlottery.co.kr/gameResult.do?method=byWin&drwNo={win_result}'

html = urllib.request.urlopen(url).read()
soup = BeautifulSoup(html, 'html.parser')

numWin = soup.select('.num.win,.num.bonus')

lotto = []
for i in numWin:
print(i.text)














댓글

이 블로그의 인기 게시물

[python] 1. 파이썬 라이브러리 설치 및 버전확인

[python] 4. 파이썬 파일 불러올때 설정 (데이터양, 인덱스 설정)

[파이썬 실습] 랜덤 타자 게임 만들기 - while, random, time