从 http://www.lottery.gov.cn/ 抓取 体彩 排列5 历史数据
python 2.7 : get_pl5.py
# -*- coding: utf-8 -*-
import os,sys
import urllib
import urllib2
from BeautifulSoup import BeautifulSoup
# 体彩 排列5
URL = "http://www.lottery.gov.cn/historykj/history.jspx?_ltype=plw"
page = urllib2.urlopen(URL)
soup = BeautifulSoup(page)
page.close()
fp = open("pl5.txt","w")
tables = soup.findAll('table')
tab = tables[0]
for tr in tab.tbody.findAll('tr'):
for td in tr.findAll('td'):
text = td.getText().encode('cp936')+'!'
fp.write(text)
fp.write('\n')
#
fp.close()
python 3.7 : pip install beautilfulsoup4
# -*- coding: utf-8 -*-
import os,sys
from urllib imp