[Tutor] Help with Temperature Program

Alexandre Ratti alex@gabuzomeu.net
Mon, 27 May 2002 16:45:11 +0200


Hi Joe,


At 09:53 27/05/2002 -0400, you wrote:
>From: "Joe Kessel" <jkessel@sas.upenn.edu>
>Date: Sun, 26 May 2002 23:15:36 -0700
>Subject: [Tutor] Help with Temperature Program

>Im very new to programming and python.  I need to write a simple 
>program  that extracts the current temperature off weather.com.  If anyone 
>is willing to give me some basic instructions, I would appreciate it.

OK, here are suggestions to get you started.

1) First, if you haven't already done so, go through the tutorial so that 
you can pick up the basics:

http://www.python.org/doc/current/tut/tut.html

See also:

http://www.python.org/doc/Newbies.html


2) Then, try retrieving the text content of the Web page you're interested 
in. To access a Web page, you can use the "urllib" module. Eg.

import urllib
theURL = """http://www.weather.com/weather/local/FRXX0076?y=10&x=8"""

# Access the page
thePage = urllib.urlopen(theURL)
# Store the page content in a variable
pageText = thePage.read()
# Close the page object
thePage.close()

3) Then, try to extract the data you're interested in from the page.
To extract data from the page text you downloaded, one solution is using 
regular expressions (the "re" module). You may find them a tad complex, but 
they offer a lot of flexibility. If you want to use regular expressions, 
take a look at this tutorial:

http://py-howto.sourceforge.net/regex/regex.html


If you're stuck, let us know and we'll try to help.


Cheers.

Alexandre