-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfind_posted_lineups.py
More file actions
33 lines (24 loc) · 1.17 KB
/
Copy pathfind_posted_lineups.py
File metadata and controls
33 lines (24 loc) · 1.17 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
32
33
from bs4 import BeautifulSoup
import urllib2
link = "http://www.rotowire.com/baseball/daily_lineups.htm"
page = urllib2.urlopen(link)
soup = BeautifulSoup(page, "lxml")
def get_posted_lineups():
lineups = soup.find_all('div', attrs={'class': 'span15 dlineups-mainbox'})
# teams with lineups
twl = []
for l in lineups:
mainbar = l.find('div', attrs={'class': 'span15 dlineups-mainbar'})
away = mainbar.find('div', attrs={'class': 'dlineups-mainbar-away'})
home = mainbar.find('div', attrs={'class': 'dlineups-mainbar-home'})
awayteam = away.find('a')
# just return the team abbreviation found in the parameters of the link
at = awayteam['href'][(len(awayteam['href'])-awayteam['href'].find('=')-1)*-1:]
hometeam = home.find('a')
# just return the team abbreviation found in the parameters of the link
ht = hometeam['href'][(len(hometeam['href'])-hometeam['href'].find('=')-1)*-1:]
# t = teams['href'][(len(teams['href'])-teams['href'].find('=')-1)*-1:]
if not l.find_all('div', attrs={'class': 'dlineups-empty'}):
twl.append(at + "@" + ht)
return twl
get_posted_lineups()