[Tutor] weather scraping with Beautiful Soup

Che M pine508 at hotmail.com
Fri Jul 17 23:27:33 CEST 2009



OK, got the very basic case to work when using Beautiful Soup 3.0.7a and scraping the Weather Underground Lite page.  That gives me the current temperature, etc.  Good.

But now I would like the average temperature from, say, yesterday.  I am again having trouble finding elements in the soup.  This is the code:

----------------------
import urllib2
from BeautifulSoup import BeautifulSoup

url = "http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=KPAJAMES1&month=7&day=16&year=2009"
page = urllib2.urlopen(url)
soup = BeautifulSoup(page)

table = soup.find("td",id="dataTable tm10")
print table

------------------------

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>
--------------

And yet when I run the above code, what it prints is:

>> None

In other words, it is not finding that table.  Why?  

Help appreciated again.
Che


_________________________________________________________________
Lauren found her dream laptop. Find the PC that’s right for you.
http://www.microsoft.com/windows/choosepc/?ocid=ftp_val_wl_290
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090717/6fb7b3ee/attachment.htm>


More information about the Tutor mailing list