I'm new to python so I apologize for any rookie mistakes. I followed a tutorial to scrape stock prices from python but after fixing it to work in python 3 when I tried to adapt it to other elements of the Yahoo Finance page such as P/E ratios and Beta the output was just empty square brackets.
import urllib.request
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.request.urlopen(url)
htmltext = htmlfile.read()
regex = b'<th scope="row" width="48%">"P/E "<span class="small">(ttm)</span>: </th><td class="yfnc_tabledata1">(.+?)</td>'
pattern = re.compile(regex)
price_to_earnings = str(re.findall(pattern,htmltext))
print ("The price to earnings of " + symbolslist[i]+ " is " + price_to_earnings)
i+=1
this was the output
The price to earnings of aapl is []
The price to earnings of spy is []
The price to earnings of goog is []
The price to earnings of nflx is []
>>>