2016-07-05 12 views
1

ich nur „MLB“ Partituren von der folgenden Website zu kratzen versuchen: www.scoresandodds.com/pgrid_20160628.html?sort=rotScrape-Website basierend auf Spanne Text

Ein Abschnitt des HTML-Code wie folgt aussieht :

<div xmlns:dat="http://scoresandodds.com/dataset-main" class="section"> 
<div class="heading">< 
span class="league">MLB</span> 
<span class="date">06/28/2016</span> 
</div><table cellpadding="0" summary="" cellspacing="0" border="0"><thead> 
<tr><th class="first">Team</th><th>Pitcher</th><th>Open</th><th>Current</th><th>Runline</th><th>Scores</th><th>Notes</th> 
</tr></thead><tbody><tr><td class="teamName">901 <a href="http://scoresandodds.com/statfeed/statfeed.php?page=MLB/MLBteam&amp;teamid=NY+METS&amp;season=">NEW YORK METS</a></td> 
<td class="pitcher">(r) harvey, m</td> 
<td class="line">8</td> 
<td class="line">8.5o15</td> 
<td class="line">+1.5(-200)</td> 
<td class="score">0 Under 8.5</td> 

mit My Code beginnt:

url = "http://www.scoresandodds.com/pgrid_"+date+".html?sort=rot" 
soup = BeautifulSoup(urllib2.urlopen(url), 'html.parser') 
scores = soup.find_all("span", {"class": "league"}) 

print(scores) 
[<span class="league">MLB</span>, <span class="league">WNBA</span>] 

Was es gibt ist sehr gut, aber ich bin nicht klar, wie die Daten nur kratzen für "MLB" Scores.

Antwort

2

Suchen Sie die MLB "label" und bekommen das erste folgende table nur über find_next():

mlb_table = soup.find("span", class_="league", text="MLB").find_next("table") 
+0

Herrlich - Danke! –

Verwandte Themen