"""爬取双色球开奖号码"""
import requests
import re
def Crawl_twoball(page = 10001):
"""爬取网页路径"""
url = 'http://kaijiang.500.com/shtml/ssq/' + str(page) + '.shtml'
reponse = requests.get(url)
html = reponse.text
"""检测是否有这期"""
notfound = re.findall('<head><title>(.*?) Not Found</title></head>', html)
if notfound:
return 0
"""获取红球,蓝球号码"""
blueball = re.findall('<li class="ball_blue">(.*?)</li>', html)
redball = re.findall('li class="ball_red">(.*?)</li>', html)
twoball = redball + blueball
"""‘保存数据"""
with open('twoball.txt', 'a+') as f:
f.write(str(page) + '\000')#期号
for i in twoball:
f.write(i + '\000')
f.write('\n')
return 1
j = 10001 #起始期号
while j < 20010: #结束期号
a = Crawl_twoball(j)
#一年有153期左右,跳过中间空白
if a == 0:
j = (j//1000 + 1) * 1000
j += 1
python爬取双色球以往开奖号码
最新推荐文章于 2024-10-11 14:13:13 发布