input: Write a function to extract the latest stock prices from specific websites using web scraping in Python. The function should take a list of stock names as input and return the current stock prices as a list. Each stock name is in the format "StockSymbol stocks" (e.g., "AAPL stocks"). The function should print the price of each stock. If the stock name is not valid, the function should handle the exception and print an error message.
  import requests
  from bs4 import BeautifulSoup
  
  def get_stock_prices(stocks):
      def get_stock_price(stock):
          try:
              url = f"https://finance.yahoo.com/quote/{stock}"
              response = requests.get(url)
              soup = BeautifulSoup(response.text, 'html.parser')
              price = soup.find('div', {'class': 'My(6px) Pos(r) smartphone_Mt(6px)'}).find('span').text
              return price
          except Exception as e:
              return f"Error fetching price for {stock}: {e}"
  
      for stock in stocks:
          price = get_stock_price(stock)
          print(f'The price of {stock} is {price}.')
  
  assert get_stock_prices(["AAPL stocks", "MSFT stocks", "FB stocks", "GOOG stocks"]) == None
  assert get_stock_prices(["INVALID stocks"]) == None
output: def get_stock_prices(stocks):
      def get_stock_price(stock):
          try:
              url = f"https://finance.yahoo.com/quote/{stock}"
              response = requests.get(url)
              soup = BeautifulSoup(response.text, 'html.parser')
              price = soup.find('div', {'class': 'My(6px) Pos(r) smartphone_Mt(6px)'}).find('span').text
              return price
          except Exception as e:
              return f"Error fetching price for {stock}: {e}"
  
      for stock in stocks:
          price = get_stock_price(stock)
          print(f'The price of {stock} is {price}.')