input: Write a function to scrape an online news website to get the headlines. The function should return a list of headlines retrieved from the specified URL. If the URL is invalid or unreachable, the function should return an empty list.
  
  def scrape_headlines(url):
      try:
          # get the response in the form of html
          r = requests.get(url) 
          r.raise_for_status()
          
          # create a beautifulsoup object to parse contents 
          soup = BeautifulSoup(r.content, 'html5lib') 
          
          # find headlines from the parsed page  
          headlines = [headline.text for headline in soup.find_all('h2')]
          
          return headlines
      except:
          return []
  
  assert scrape_headlines("https://www.news.com/") == ["First Headline", "Second Headline", "Third Headline"]
  assert scrape_headlines("http://invalid-url.com") == []
  assert scrape_headlines("https://www.non-existent-news-site.com/") == []
output: def scrape_headlines(url):
      try:
          r = requests.get(url) 
          r.raise_for_status()
          soup = BeautifulSoup(r.content, 'html5lib') 
          headlines = [headline.text for headline in soup.find_all('h2')]
          return headlines
      except:
          return []