I'm currently getting price data from Yahoo Finance through a simple web-scraper, but it's taking 1.3-1.5 seconds per request. Ideally, I would like this to be < 1 second, so is there a way to make this faster? I'm just learning Python, so maybe there's a more optimized version of this, but I can't seem to find anything.
import requests
import bs4
from bs4 import BeautifulSoup
def getYahooPrice():
r = requests.get("https://finance.yahoo.com/quote/AAPL?p=AAPL")
soup = BeautifulSoup(r.text,"lxml")
stocks = soup.find_all('div', class_ = 'My(6px) Pos(r) smartphone_Mt(6px)')[0].find('span').text
print(stocks)
getYahooPrice()