[Tutor] weather scraping with Beautiful Soup

Sander Sweers sander.sweers at gmail.com
Sat Jul 18 01:09:32 CEST 2009


2009/7/17 Che M <pine508 at hotmail.com>:
> table = soup.find("td",id="dataTable tm10")

Almost right. attrs should normall be a dict so {'class':'dataTable
tm10'} but you can use a shortcut, read on.

> ------------------------
>
> When I look at the page source for that page, there is this section, which
> contains the "dataTable tm10" table I want to zoom in on:
>
> ------------
> <table cellspacing="0" cellpadding="0" class="dataTable tm10">
> 		<thead>
> 		<tr>
> 		<td style="width: 25%;">&nbsp;</td>
> 		<td>Current:</td>
> 		<td>High:</td>
> 		<td>Low:</td>
> 		<td>Average:</td>
> 		</tr>
> 		</thead>
> 		<tbody>
> 		<tr>
> 		<td>Temperature:</td>
> 		<td>
>   <span class="nobr"><span class="b">73.6</span>&nbsp;&#176;F</span>
> </td>
> 		<td>
>   <span class="nobr"><span class="b">83.3</span>&nbsp;&#176;F</span>
> </td>
> 		<td>
>   <span class="nobr"><span class="b">64.2</span>&nbsp;&#176;F</span>
> </td>
> 		<td>
>   <span class="nobr"><span class="b">74.1</span>&nbsp;&#176;F</span>
> </td>
> --------------

The tag you are looking for is table not td. The tag td is inside the
table tag. So with shortcut it looks like,

table = soup.find("table","dataTable tm10")

or without shortcut,

table = soup.find("table",{'class':'dataTable tm10'})

Greets
Sander


More information about the Tutor mailing list