import urllib
import re
symbolslist = ["aaple", "spy", "goog", "nflx"]
i=0
while i<len(symbolslist):
url = "http://finance.yahoo.com/q?s=" +symbolslist[i] +"&q1=1"
htmlfile = urllib.urlopen(url)
htmltext = htmlfile.read()
regex = '<span id="yfs_184_'+symbolslist[i]'">(.+?)</span>'
pattern = re.compile(regex)
price = re.findall(pattern,htmltext)
print "the price of", symbolslist[i]," is " ,price
i+1
有人能告诉我上面的代码有什么问题吗? 谢谢
您丢失了
+
符号:使用format-it使代码更具可读性https://pyformat.info/
你错过了
regex = '<span id="yfs_184_'+symbolslist[i]'">(.+?)</span>'
的第二个+
线路
在
symbolslist[i]
之后需要+
:相关问题 更多 >
编程相关推荐