[No.003-1]爬虫网易赔率数据并导入到mysql数据库

来源:互联网 发布:尤里盖勒 知乎 编辑:程序博客网 时间:2024/06/07 03:42
#encoding:utf-8import urllib2from bs4 import BeautifulSoupwebsite = "http://caipiao.163.com/order/jczq-hunhe/#from=leftnav"page = urllib2.urlopen(website)soup = BeautifulSoup(page)'''获取场次以及分数合集比如比分对应代码表:11对应:1:170对应:胜其他77对应:平其他07对应:负其他因此场次和比分结合为,017-10,017-20,017-21'''#场次信息 screeningi = 1screening = []for item in soup.findAll("span",{"class":"co1"}):    screening.append(item.i.string+'\n')    i+=1sc = open('sc.txt','w')sc.writelines(screening)sc.close()#比分标题 bifenbifen=["1:0","2:0","2:1","3:0","3:1","3:2","4:0","4:1","4:2","5:0","5:1","5:2","胜其他","0:0","1:1","2:2","3:3","平其他","0:1","0:2","1:2","0:3","1:3","2:3","0:4","1:4","2:4","0:5","1:5","2:5","负其他"]#场次+比分:ccbfccbf = []for item_jtip in screening:    for item_bifen in bifen:        ccbf.append(item_jtip+item_bifen)#之后遍历ccbffor item in ccbf:    print item#得到结果集如(场次为3位数字,第一个为主场比分,中间为冒号,最后一个为客场比分):0281:10282:20283:3028平其他0280:10280:20281:20280:30281:30282:30280:40281:40282:40280:50281:5#----------------'''这里因为使用的是python2,所以需要将str->Unicode具体参考:http://blog.csdn.net/mindmb/article/details/7898528'''#建立比分赔率字典bfpl#获取比分赔率bfpl = []for item in soup.findAll("td",{"gametype":"bf"}):    bfpl.append(item.find("div").string+'\n')#写入到文件bf.txtbf = open('bf.txt','w')bf.writelines(bfpl)bf.close()#组合bfdata = {}bf = dict(zip(ccbf,bfpl))#--------------------#出现错误!!!#bfpl获取的数量和ccbf数量不一致,重新使用一个队列,同时获取场次和比分的赔率数据放置在一个队列中
0 0