stock quotes

Larry Bates larry.bates at websafe.com
Wed Sep 13 22:33:08 EDT 2006


Donlingerfelt wrote:
> I would like to download stock quotes from the web, store them, do
> calculations and sort the results.  However I am fairly new and don't have a
> clue how to parse the results of a web page download.   I can get to the
> site, but do not know how to request the certain data  need.  Does anyone
> know how to do this?  I would really appreciate it.  Thanks.
> 
> 
It depends:

If the HTML on the page(s) you want to process is clean and well formed it
can be pretty easy.  Download elementree from:

http://effbot.org/zone/element-index.htm

This will be included in Python 2.5 standard library, but for 2.4 and
older you need to download it.

If the HTML on the page(s) is not clean or well formed.  Parsing the
HTML can be "messey".  There is a module called BeautifulSoup that is
pretty good at this.  You will need to get it from:

http://www.crummy.com/software/BeautifulSoup/#Download

In addition you will want to use the standard library urllib module
to connect to and read the information you want to parse.

Start with urllib and get it to read your HTML first, then use either
elementtree or beautifulsoup to parse it and extract the data you
want to get.

Note: If the web page gets changed, it can break your program.

Hope information helps.

-Larry



More information about the Python-list mailing list