def PLR(): my_url = "http://www.skysports.com/premier-league-results" cb = urlO(my_url) page = cb.read() html_soup = bs(page, "html.parser") AwayL = [] HomeL = [] HSL = [] ASL = [] ResultL = [] DateL =[] TeamHome = html_soup.find('div', attrs={'class': 'fixres__body'}) Date2 = TeamHome.findAll('a', attrs={'class': 'matches__item matches__link'}) Date1 = TeamHome.findAll('h4', attrs={'class': 'fixres__header2'}) for time in Date1: Date = time.text DateL.append(Date) for time in Date2: Home1 = time.findAll('span',attrs={'class': 'matches__item-col matches__participant matches__participant--side1'}) for i in Home1: Home = i.text.strip() HomeL.append(Home) HomeScore= time.findAll('span',attrs={'class': 'matches__teamscores-side'})[0] for i in HomeScore: HS = int(i) HSL.append(HS) AwayScore=time.findAll('span',attrs={'class': 'matches__teamscores-side'})[1] for i in AwayScore: AS = int(i) ASL.append(AS) Away1 = time.findAll('span', attrs={'class': 'matches__item-col matches__participant matches__participant--side2'}) for i in Away1: Away = i.text.strip() AwayL.append(Away) Result = 'D' for i in HSL: H = i for i in ASL: if i > H: Result = 'A' elif i < H: Result = 'H' else: Result = 'D' ResultL.append(Result) test_df = pd.DataFrame({'Home': HomeL, 'HS': HSL, 'AAS': ASL, 'Away': AwayL, 'Results': ResultL }) engine = create_engine("mysql://*****:*****@localhost/football") test_df.to_sql(name='PLR',con=engine,schema='football',if_exists='replace')
def main(): s = [] for linkr in links: cb = urlO(linkr) page = cb.read() html_soup = bs(page, "html.parser") u4 = html_soup.find('ul', attrs={'class': 'page-nav__item-group'}). \ find_all('li', attrs={'class': 'page-nav__item'})[8].find('a', attrs={'class': 'page-nav__link'})\ ['href'].replace('http://www.skybet.com/go/class/5/type/1?aff=1010', '').encode("utf8") s = [i for i in s if i != ''] s.append(u4) print(s) for l in s: MStat(l)
def UPLR(): my_url = "http://www.skysports.com/premier-league-fixtures" cb = urlO(my_url) page = cb.read() html_soup = bs(page, "html.parser") AwayL = [] HomeL = [] HSL = [] DateL = [] TeamHome = html_soup.find('div', attrs={'class': 'fixres__body'}) Date2 = TeamHome.findAll('a', attrs={'class': 'matches__item matches__link'}) Date1 = TeamHome.findAll('h4', attrs={'class': 'fixres__header2'}) for time in Date1: if time.text == time.text: MatchDate = time.text print MatchDate DateL.append(MatchDate) for time in Date2: Home1 = time.findAll('span', attrs={'class': 'matches__item-col matches__participant matches__participant--side1'}) for i in Home1: Home = i.text.strip() Home = str(Home) DateL.append(Home) HomeScore = time.findAll('span', attrs={'class': 'matches__date'}) for i in HomeScore: MatchTime = i.text.strip() print MatchTime DateL.append(MatchTime) Away1 = time.findAll('span', attrs={ 'class': 'matches__item-col matches__participant matches__participant--side2'}) for i in Away1: Away = i.text.strip() Away = str(Away) DateL.append(Away) sql(Away, MatchTime, MatchDate, Home)
def MStat(U): years = "17-18" cb = urlO(U) page = cb.read() soup = bs(page, "html.parser") time = soup.find('ul', attrs={ 'class': 'match-head__detail' }).find_all('li', attrs={'class': 'match-header__detail-item'})[1].text MatchTime = time[0:6] MatchDate = time[7:] Head = soup.findAll('a', attrs={'class': 'match-head__team-name'}) Home = soup.findAll('abbr', attrs={'class': 'swap-text--bp10'})[0]['title'] print(Home) HS = soup.find('span', attrs={'class': 'match-head__score'}).text.strip() Head2 = soup.findAll('a', attrs={'class': 'match-head__team-name'}) Away = soup.findAll('abbr', attrs={'class': 'swap-text--bp10'})[1]['title'] print Away AAS = soup.findAll('span', attrs={'class': 'match-head__score'})[1].text.strip() Result = 'D' if int(AAS) > int(HS): Result = 'A' elif int(AAS) < int(HS): Result = 'H' else: Result = 'D' HeadDetails = soup.findAll("ul", {"class": "match - head__detail"}) for HeadDetail in HeadDetails: HeadDetailn = HeadDetail.findAll('li', attrs={ "class": "match-header__detail-item" }).text HeadDetailsL.append(HeadDetailn) print(HeadDetailsL) All = soup.findAll("span", {"class": "match-stats__bar"}) for i in All: i = soup.findAll(attrs={"class": "match-stats__away"}) data = [ ele.text.strip().encode("utf8").replace('away\n', '') for ele in i ] # Data.append([ele for ele in int if ele]) AP = "" ASTotal = "" ASHOnTarget = "" ASBlocked = "" AKPass = "" ACross = "" ACorners = "" AOffsides = "" AInterceptions = "" AGSaves = "" AFouls = "" for i in All: i = soup.findAll(attrs={"class": "match-stats__home"}) Homes = [ ele.text.strip().encode("utf8").replace('home\n', '') for ele in i ] # Data.append([ele for ele in str if ele]) HP = "" HSTotal = "" HSHOnTarget = "" HSBloked = "" HKPass = "" HCross = "" HCorners = "" HOffsides = "" HInterceptions = "" HGSaves = "" HFouls = "" make_result(AP, ASHOnTarget, ASBlocked, AKPass, ACross, ACorners, AOffsides, AInterceptions, AGSaves, AFouls, HP, HSTotal, HSHOnTarget, HSBloked, HKPass, HCross, HCorners, HOffsides, HInterceptions, HGSaves, HFouls) for HS in HSL: print(HS) sql(AP, ASTotal, ASHOnTarget, ASBlocked, AKPass, ACross, ACorners, AOffsides, AInterceptions, AGSaves, AFouls, Away, AAS, Result, HS, Home, HP, HSTotal, HSHOnTarget, HSBloked, HKPass, HCross, HCorners, HOffsides, HInterceptions, HGSaves, HFouls, MatchTime, MatchDate, years)
attrs={ 'class': 'swap-text__target' }).text.replace(' ', '') cursor = cnx.cursor() sql = "INSERT INTO Player (PlayerName, PLD, G, YC, RC, FF, Team) VALUES (%s, %s, %s, %s, %s, %s, %s);" data = (str(PlayerName).replace('-', '0'), str(PLD)[0:2].replace('-', '0'), str(G).replace('-', '0'), str(YC).replace('-', '0'), str(RC).replace('-', '0'), str(FF).replace('-', '0'), str(Team)) cursor.execute(sql, data) print(str(PlayerName), str(PLD), str(G), str(YC), str(RC), str(FF), str(Team)) cnx.commit() my_url = "http://www.skysports.com/bournemouth" cb = urlO(my_url) page = cb.read() html_soup = bs(page, "html.parser") f = html_soup.find('optgroup') TeamTableName = f.find_all('option') for o in TeamTableName: x = o['value'] print(x) my_url = "http://www.skysports.com{}-stats".format(x) cb = urlO(my_url) page = cb.read() html_soup = bs(page, "html.parser") tableClass = 'table -small no-wrap football-squad-table ' T = True #Delete(T) i = 0