贴出来一串代码大家看看

#!usr/bin/python
#encoding:utf8
#author:cosme
from time import ctime
from urllib import urlopen
import re

ticks = ('YHOO','GOOG','EBAY','AMZN')
URL = 'http://quote.yahoo.com/d/quotes.csv?s=%s&f=slcp2'

print '\nPrices quoted as of: ',ctime()
print '\nTICKER'.ljust(9),'PRICE'.ljust(8),'CHG'.ljust(5),'%AGE'
print '------'.ljust(8),'-----'.ljust(8),'-----'.ljust(5),'-----'

u = urlopen(URL %','.join(ticks))

for row in u:
    tick, price, chg, per = row.split(',')
    mo = re.compile(r'.*>(?P<price>\d+\.\d+)<*').match(price).group('price')
    print eval(tick).ljust(7), mo.rjust(6),chg.rjust(6),eval(per).rjust(6)
 
 
不知道不使用正则可以实现不。。。
 

你可能感兴趣的:(贴出来一串代码大家看看)