stock quotes
Frederic Rentsch
anthra.norell at vtxmail.ch
Thu Sep 14 07:44:20 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.
>
>
>
Hi,
Heres's example 8.4 from the SE manual:
----------------------------------------------------------------------------------------------------------------------------------
> >> def get_current_stock_quotes (symbols):
import urllib
url = 'http://finance.yahoo.com/q/cq?d=v1&s=' + '+'.join (symbols)
htm_page = urllib.urlopen (url)
import SE
keep = '"~[A-Z]+ [JFMAJSOND].+?%~==(10)" "~[A-Z]+
[0-9][0-2]?:[0-5][0-9][AP]M.+?%~==(10)"'
Data_Extractor = SE.SE ('<EAT> ' + keep)
Tag_Stripper = SE.SE ('"~<(.|\n)*?>~= " se/htm2iso.se | "~\n[
\t\n]*~=(10)" "~ +~= "')
data = Data_Extractor (Tag_Stripper (htm_page.read ()))
htm_page.close ()
return data
> >> print get_current_stock_quotes (('GE','IBM','AAPL', 'MSFT', 'AA',
'MER'))
GE 3:17PM ET 33.15 0.30 0.90%
IBM 3:17PM ET 76.20 0.47 0.61%
AAPL 3:22PM ET 55.66 0.66 1.20%
MSFT 3:22PM ET 23.13 0.37 1.57%
AA 3:17PM ET 31.80 1.61 4.82%
MER 3:17PM ET 70.24 0.82 1.15%
-----------------------------------------------------------------------------------------------------------------------------
If this meets your requirements you'll find SE here:
http://cheeseshop.python.org/pypi/SE/2.2%20beta
Regards
Frederic
More information about the Python-list
mailing list