Used this tutorial to scrape stock prices: https://www.youtube.com/watch?v=f2h41uEi0xU
There are some similar questions, but I want to know how to fix this current code (for learning purposes) where these just have work arounds.
Web scraping information other than price from Yahoo Finance in Python 3
Using Regex to get multiple data on single line by scraping stocks from yahoo
I understand there are better ways to do this, however these videos are helpful to learn.
Everything is working, but it isn't retrieving the prices from the site! I have the exact code he has too. I am using Python Launcher (Mac) 2.7 (tried 3.4 as well) to run the python program.
Here's my code:
import urllib
import re
symbolslist = ["aapl", "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_l84_'+symbolslist[i] +'">(.+?)</span>'
pattern = re.compile(regex)
price = re.findall(pattern,htmltext)
print "the price of" , symbolslist[i], " is " ,price
i+=1