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

"your_name" <your_email_address at> wrote in message
news:3C59FF86.9B211598 at
> 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
> 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=""
> 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) +
    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


More information about the Python-list mailing list