-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataCollection.py
More file actions
32 lines (25 loc) · 1.04 KB
/
dataCollection.py
File metadata and controls
32 lines (25 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import json
import urllib2
from BeautifulSoup import BeautifulSoup
url = "http://espn.go.com/nfl/matchup?gameId=400791489"
soup = BeautifulSoup(urllib2.urlopen(url).read())
teams = soup.findAll('table')[0].tbody.findAll('tr')
full_results = soup.findAll('table')[1].tbody.findAll('tr')
list = []
list_headers = []
list_home = []
list_away = []
print(teams)
for child in teams:
team = ''.join(child.findAll('td')[0].contents).encode('utf-8').strip()
score = ''.join(child.findAll('td')[5].contents).encode('utf-8').strip()
list.append("{},{},".format(team,score))
return list
#for child in full_results:
# headers = ''.join(child.findAll('td')[0].contents).encode('utf-8').strip()
# list_headers.append("{}".format(headers))
# home_team = ''.join(child.findAll('td')[2].contents).encode('utf-8').strip()
# list_home.append("{}".format(home_team))
# away_team = ''.join(child.findAll('td')[1].contents).encode('utf-8').strip()
# list_away.append("{}".format(away_team))
# print "{},{},{}".format(headers,home_team,away_team)