Python

Emile van Sebille emile at fenx.com
Fri Feb 1 04:20:12 CET 2002


"your_name" <your_email_address at upenn.edu> wrote in message
news:3C59FF86.9B211598 at upenn.edu...
> I'm trying to write a Python script that looks up the current value of
> the NASDAQ on 2 different webpages and compares the values.  I'm
having
> some difficulties in figuring out how to grab the index values off of
> the websites.  The codes i'm familar with are below.  any suggestions?
>
>
> import urllib
> cnnnasdaq="http://money.cnn.com/markets/nasdaq.html"
> cnnpage=urllib.urlopen(cnnnasdaq).read()
>

This seems to do it...(at the moment...)

def getcnnvalue(market, cnnpage):
    marketstart = cnnpage.find("<!--MARKETSTART: %s -->" % market)
    datatag = '<td class="chartdata">'
    chartdata = cnnpage[marketstart:].find(datatag) + len(datatag) +
marketstart
    value = cnnpage[chartdata:chartdata +
cnnpage[chartdata:].find(' ')]
    return value



print '\n\n', getcnnvalue('sandp', cnnpage)

print '\n\n', getcnnvalue('nasdaq', cnnpage)


--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list