Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. from bs4 import BeautifulSoup
  2. import requests
  3. import pandas as pd
  4. import numpy as np
  5. import re
  6.  
  7. headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/574.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
  8. url = 'https://projects.fivethirtyeight.com/soccer-predictions/premier-league/'
  9.  
  10. requestResult = requests.get(url, headers=headers)
  11. soup = BeautifulSoup(requestResult.content, "lxml")
  12.  
  13. matchFrame = pd.DataFrame()
  14. homeProbs = []
  15. drawProbs = []
  16. awayProbs = []
  17. homeTeams = []
  18. awayTeams = []
  19. matches = soup.find_all('div', class_='match-container')
  20. for match in matches:
  21.     homeProbs.append(convertToDecimal(match.find(class_="match-top").find(class_="prob").text))
  22.     drawProbs.append(convertToDecimal(match.find(class_="match-top").find(class_="tie-prob").text))
  23.     awayProbs.append(convertToDecimal(match.find(class_="match-bottom").find(class_="prob").text))
  24.     homeTeams.append(match['data-team1'])
  25.     awayTeams.append(match['data-team2'])
  26.    
  27. matchFrame['homeTeam'] = pd.Series(homeTeams)
  28. matchFrame['awayTeam'] = pd.Series(awayTeams)
  29. matchFrame['homeProb'] = pd.Series(homeProbs)
  30. matchFrame['drawProb'] = pd.Series(drawProbs)
  31. matchFrame['awayProb'] = pd.Series(awayProbs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement