擅长:python、mysql、java
<pre><code>import urllib.request
import re
Symbols = ['aapl', 'spy' , 'goog' , 'nflx']
i = 0
while i < len(Symbols):
Yahoo='http://finance.yahoo.com/q?s=' + Symbols[i]
htmlfile = urllib.request.urlopen(Yahoo)
htmltext = htmlfile.read()
string = Symbols[i]
symbol = string.encode('utf-8')
pattern= re.compile(b'<span id="yfs_l84_'+ symbol +b'">(.+?)</span>')
price= re.findall(pattern, htmltext)
print('The price of' + str(Symbols[i]) + ' is ' + str(price))
i+=1
Hai try this it works
</code></pre>