赞
踩
- import urllib
-
- link="http://finance.yahoo.com/q/cp?s=^STI"
-
- html=urllib.urlopen(link).read()
-
- from sgmllib import SGMLParser
- import time
- class 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=1
- self.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'] #hack
- names=[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)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。