成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

[No.003-4]爬蟲網(wǎng)易賠率數(shù)據(jù)并導(dǎo)入到mysql數(shù)據(jù)庫

BlackHole1 / 2748人閱讀

摘要:收集比賽結(jié)果場次先獲得包含和其他信息的隊列賽事類型比賽日期刪除無效的前個數(shù)據(jù)主隊,客隊勝平負賠率刪除首尾兩個無效數(shù)據(jù)比分結(jié)果以及比分結(jié)果賠率形成場次日期唯一裝配結(jié)果集更新數(shù)據(jù)庫內(nèi)容更新勝平負勝其他平其他負其他更新總進球勝其

收集比賽結(jié)果
#encoding:utf-8
import sys
import urllib2
import re
from bs4 import BeautifulSoup
import MySQLdb as mdb

reload(sys)
sys.setdefaultencoding("utf-8")
soup = BeautifulSoup(open("20140830"))


#1.場次 
#先獲得temp(包含None和其他信息的隊列)
scr = []
temp =[]
for trs in soup.findAll("tr"):
    for tds in trs.findAll("td",{"width":"50"}):
        temp.append(tds.string)

lt = len(temp)/4
for i in range(lt):
    scr.append(temp[4*i+3])



#2.賽事類型
league = []
for item in soup.findAll("tr"):
    for item1 in item.findAll("td",{"width":"70"}):
        league.append(item1.string.encode("utf-8"))

#3.比賽日期
temp = []
gmdate = []
for item in soup.findAll("tr"):
    for item1 in item.findAll("td",{"width":"61"}):
        temp.append(item1)

#刪除無效的前3個數(shù)據(jù)
temp =temp[3:]
for item in temp:
    gmdate.append(re.search("w{4}-w{2}-w{2}",str(item)).group())




#4.主隊,客隊
team=[]
for item in soup.findAll("tr"):
    for teams in item.findAll("a",{"class":"dui"}):
        team.append(teams.string.strip().encode("utf-8"))

#5.勝平負賠率
spfpl =[]
temp = []
for trs in soup.findAll("tr"):
    for tds in trs.findAll("span"):
        temp.append(tds.string)

#刪除首尾兩個無效數(shù)據(jù)
temp =temp[1:-1]
for i in range(len(temp)):
    for item in temp[7*i+4:7*i+7]:
        spfpl.append(item)

#6.比分結(jié)果以及比分結(jié)果賠率
bfjg = []
temp = []
for trs in soup.findAll("tr"):
    for item in trs.findAll("div",{"align":"center"}):
        for item1 in item.findAll("strong"):
            bfjg.append(item1.string.encode("utf-8"))

#7.形成場次日期唯一id
ids=[]
for i in range(len(scr)):
    ids.append(gmdate[i]+"-"+scr[i])


#裝配結(jié)果集
res =[]
for i in range(len(scr)):
    res.append(ids[i])
    res.append(scr[i])
    res.append(league[i])
    res.append(gmdate[i])
    res.append(team[2*i])
    res.append(team[2*i+1])
    res.append(spfpl[3*i])
    res.append(spfpl[3*i+1])
    res.append(spfpl[3*i+2])
    res.append(bfjg[2*i])
    res.append(bfjg[2*i+1])




#更新數(shù)據(jù)庫內(nèi)容
conn=mdb.connect(host="localhost",user="root",passwd="oracle",db="betdb",port=3306)
cur = conn.cursor()
SQL="insert into results(id,lea,gmd,hos,gue,win,dog,los,res,odd) values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
l =len(res)/10
for i in range(l):
    for item in res[10*i:10*i+1]:
        cur.execute(SQL,res[10*i:10*i+10])
        i+=1


#更新勝平負
sql_update3="update results set spf=3 where res="1:0" or res="2:0" or res="2:1" or res="3:0" or res="3:1" or res="3:2" or res="4:0" or res="4:1" or res="4:2" or res="5:0" or res="5:1" or res="5:2" or res="勝其他";"

sql_update1="update results set spf=1 where res="0:0" or res="1:1" or res="2:2" or res="3:3" or res="平其他";"

sql_update0="update results set spf=0 where res="0:1" or res="0:2" or res="1:2" or res="0:3" or res="1:3" or res="2:3" or res="0:4" or res="1:4" or res="2:4" or res="0:5" or res="1:5" or res="2:5" or res="負其他";"

cur.execute(sql_update3)
cur.execute(sql_update1)
cur.execute(sql_update0)

#更新總進球
sql_updatezjq0="update results set zjq=0 where res="0:0""
sql_updatezjq1="update results set zjq=1 where res="1:0" or res="0:1""
sql_updatezjq2="update results set zjq=2 where res="2:0" or res="0:1" or res="1:1" or res="0:2""
sql_updatezjq3="update results set zjq=3 where res="3:0" or res="2:1" or res="1:2" or res="0:3""
sql_updatezjq4="update results set zjq=4 where res="4:0" or res="3:1" or res="2:2" or res="1:3" or res="0:4""
sql_updatezjq5="update results set zjq=5 where res="5:0" or res="4:1" or res="3:2" or res="2:3" or res="0:5" or res="1:4""
sql_updatezjq6="update results set zjq=6 where res="5:1" or res="3:3" or res="4:2" or res="2:4" or res="1:5""
sql_updatezjq7="update results set zjq=7 where res="勝其他" or res="負其他""

cur.execute(sql_updatezjq0)
cur.execute(sql_updatezjq1)
cur.execute(sql_updatezjq2)
cur.execute(sql_updatezjq3)
cur.execute(sql_updatezjq4)
cur.execute(sql_updatezjq5)
cur.execute(sql_updatezjq6)
cur.execute(sql_updatezjq7)

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/37366.html

相關(guān)文章

  • [No.003-0]爬蟲網(wǎng)易賠率數(shù)據(jù)導(dǎo)入mysql數(shù)據(jù)

    摘要:所以我不得不做的就是把每天的賠率數(shù)據(jù)導(dǎo)入到我自己的數(shù)據(jù)庫,根據(jù)一定的運算法則,將可能性篩選出來,然后我再做進一步的判斷。 首先,我擁有這個導(dǎo)入賠率的需求,并且,我需要的是所有的數(shù)據(jù)賠率,我需要把某些臟賠率(極有可能不會出現(xiàn)的賠率,誤導(dǎo)彩迷的賠率)刪除,并且我需要知道這些賠率的比分,刪除這些賠率,可以逆推正確比分以及賠率的區(qū)間。 所以我不得不做的就是把每天的賠率數(shù)據(jù)導(dǎo)入到...

    cikenerd 評論0 收藏0
  • [No.003-1]爬蟲網(wǎng)易賠率數(shù)據(jù)導(dǎo)入mysql數(shù)據(jù)

    摘要:獲取場次以及分數(shù)合集比如比分對應(yīng)代碼表對應(yīng)對應(yīng)勝其他對應(yīng)平其他對應(yīng)負其他因此場次和比分結(jié)合為,場次信息比分標題勝其他平其他負其他場次比分之后遍歷得到結(jié)果集如場次為位數(shù)字,第一個為主場比分,中間為冒號,最后一個為客場比分平其他 #encoding:utf-8 import urllib2 from bs4 import BeautifulSoup website = http://ca...

    Warren 評論0 收藏0
  • [No.003-5]爬蟲網(wǎng)易賠率數(shù)據(jù)導(dǎo)入mysql數(shù)據(jù)

    摘要:創(chuàng)建比賽結(jié)果數(shù)據(jù)庫導(dǎo)入結(jié)果到導(dǎo)入到數(shù)據(jù)庫中更新勝負數(shù)據(jù)插入更新勝場勝其他更新負場負其他更新平局平其他查看更新結(jié)果 創(chuàng)建比賽結(jié)果數(shù)據(jù)庫 CREATE TABLE `results` ( `id` char(14) NOT NULL, `scr` char(3) NULL , `lea` char(100) NULL , `gmd` date NULL , `hos` char...

    ybak 評論0 收藏0
  • [No.003-3]爬蟲網(wǎng)易賠率數(shù)據(jù)導(dǎo)入mysql數(shù)據(jù)庫--MySQL

    摘要:創(chuàng)建數(shù)據(jù)庫以及表,并導(dǎo)入數(shù)據(jù)創(chuàng)建數(shù)據(jù)庫創(chuàng)建表勝分數(shù)比分平負導(dǎo)入數(shù)據(jù)導(dǎo)入到數(shù)據(jù)庫中 創(chuàng)建數(shù)據(jù)庫以及表,并導(dǎo)入數(shù)據(jù) --創(chuàng)建數(shù)據(jù)庫 CREATE DATABASE `data` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; --創(chuàng)建表 --win w 勝 0 分數(shù) 1 比分 --draw d 平 --lose l 負 C...

    ztyzz 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<