Your browser inserts a <tbody>
element, but the actual source doesn't have that element:
<table id="dailyClimate" class="Container">
<tr class="TitlesAvgRecord">
<td style="padding-left:5px;">Date</td>
<td>Average<br />Low</td>
<td>Average<br />High</td>
<td>Record<br />Low</td>
<td>Record<br />High</td>
<td>Average<br />Precipitation</td>
<td>Average<br />Snow</td>
</tr>
<!-- etc. -->
See Why do browsers insert tbody element into table elements?
You could use the html5lib
parser instead (using BeautifulSoup(source, 'html5lib')
), which would also insert the element. However, you don't need to search for it, just go straight to the <tr>
rows:
for row in soup.find('table', id='dailyClimate').find_all('tr'):
or using a CSS selector:
for row in soup.select('table#dailyClimate tr'):
You'd normally only select the tbody
element if there perhaps were more than one or there was a thead
or tfooter
element you wanted to exclude.