input: Write a function to scrape an online news website to get the headlines. The function should send a GET request to the specified URL, use BeautifulSoup to parse the page, and then find and print all headlines (assumed to be in `<h2>` tags). If the URL is invalid or there are no headlines, the function should handle the error gracefully.
  assert get_headlines("https://www.news.com/")==[{"H2":"Breaking News"},{"H2":"Top Story"}]
  assert get_headlines("https://www.invalidwebsite.com/")==[]
  assert get_headlines("")==[]
output: def get_headlines(url):
      try:
          import requests
          from bs4 import BeautifulSoup
          response = requests.get(url)
          response.raise_for_status()
          soup = BeautifulSoup(response.text, 'html.parser')
          headlines = soup.find_all('h2')
          return [{"H2": headline.text} for headline in headlines]
      except:
          return []