Python BeautifulSoup 를 사용한 로또 번호 불러오기
Python BeautifulSoup 를 사용한 로또 번호 불러오기에 대해 소개한다.
공식 홈페이지는 다음과 같으며~
http://www.crummy.com/software/BeautifulSoup/
BeautifulSoup 의 설치는 pip 를 사용한다. 최신 버전은 아래 명령어로 설치 가능하다.
pip install beautifulsoup4
pip 가 설치 방법에 대해서는 아래 주소 글 참조 바란다.
2013/09/23 - [유틸] - Windows 에서 Python easy_install, pip 설치
설치가 다 완료 되었으면 아래와 같이 코딩하고 실행 시킨다.
from bs4 import BeautifulSoup
import urllib2
url='http://www.nlotto.co.kr/common.do?method=main'
page=urllib2.urlopen(url)
soup = BeautifulSoup(page.read())
hoi = soup.find('span', id="lottoDrwNo")
print hoi.string + "hoi"
print " "
list=[]
for n in range(1,7):
strV="drwtNo" + str(n)
first = soup.find('img', id=strV)['alt']
list.append(first)
print first
print " "
bonus = soup.find('img', id="bnusNo")['alt']
print bonus
다음과 같이 로또 번호를 읽어오는 것을 확인 할 수 있다.