Я новичок в python, поэтому прошу прощения за любые ошибки новичка. Я следовал руководству по извлечению цен на акции из Python, но после исправления его для работы в Python 3, когда я пытался адаптировать его к другим элементам страницы Yahoo Finance, таким как коэффициенты P / E и бета-версия, на выходе были просто пустые квадратные скобки.
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
это был выход
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 []
>>>