我正在编写一个教程,以从 Yahoo Fiances 中提取不同的股票价格。我有这段代码可以工作,但会打印出句子不同股票代码的价格,然后是数组括号而不是价格。非常感谢所有帮助。
import urllib
import re
symbolslist = ["aapl", "spy", "goog", "nflx"]
i = 0
while i < len(symbolslist):
url = "http://finance.yahoo.com/q?s=" + symbolslist[i] + "&ql=1"
htmlfile = urllib.urlopen(url)
htmltext = htmlfile.read()
regex = '<span id="yfs_l84_' + symbolslist[i] + ' "> (.+?) </span>'
pattern = re.compile(regex)
price = re.findall(pattern, htmltext)
print "the price of ", symbolslist[i], " is ", price
i += 1