该模块由CoreyGoldberg提供。
程序:
import urllibimport redef get_quote(symbol): base_url = 'http://finance.google.com/finance?q=' content = urllib.urlopen(base_url + symbol).read() m = re.search('id="ref_694653_l".*?>(.*?)<', content) if m: quote = m.group(1) else: quote = 'no quote available for: ' + symbol return quote用法示例:
import stockquoteprint stockquote.get_quote('goog')更新 :更改了正则表达式以匹配Google财经的最新格式(截至2011年2月23日)。这证明了依靠屏幕抓取时的主要问题。



