#http://finance.yahoo.com/q?s=spy
import urllib.request
import re
htmlfile = urllib.request.urlopen("http://finance.yahoo.com/q?s=spy")
htmltext = htmlfile.read().decode("utf-8")
regex = re.compile('<span id="yfs_184_spy">(.+?)</span>')
regex1 = re.compile('<span id="yfs_l84_spy">(.+?)</span>')
regex2 = re.compile('<span id="yfs_184_spy">(.+?)</span>')
price = re.findall(regex, htmltext)
price2 = re.findall(regex1, htmltext)
price3 = re.findall(regex2, htmltext)
price4 = re.findall(regex, htmltext)
print(price)
print(price2)
print(price3)
print(price4)
the code above returns this result:
[]
['197.55']
[]
[]
I have no idea why the other regex variables do not return any match objects (price, price3, price 4). Price2 variable html regex pattern was copied from the source of the URL and pasted into the editor which worked. When I type out the HTML for some reason it won't return a match object. Thanks so much for any help in advanced.