stocks

来源:互联网 发布:java collection用法 编辑:程序博客网 时间:2024/05/14 20:46
import urllib  link="http://finance.yahoo.com/q/cp?s=^STI"html=urllib.urlopen(link).read()from sgmllib import SGMLParserimport timeclass URLLister(SGMLParser):    urls = []    cou=0    is_td=""    def start_td(self, attrs):href = [v for k, v in attrs if k=='class']if 'yfnc_tabledata1' in href:self.is_td=1self.cou+=1    def end_td(self):self.is_td=""    def handle_data(self,text):if self.is_td:self.urls.append(text)while True:print 'Symbol','Name    ','LastTrade    ','Change    ','Volume    'lister=URLLister()lister.feed(html)exclusive=['&','C',' N'] #hacknames=[x for x in lister.urls if x!=' ' and  not (x in exclusive) ]lenght=len(names)for i in range(0,lenght,7):print names[i:i+7]print '===================================================================='print 'will start to work in 1 min'time.sleep(60)

原创粉丝点击