input: Write a function to scrape the table from the given URL and extract the planets' information including name, mass, and distance from the sun. The function should return a list of dictionaries where each dictionary contains the details of a planet. If the URL is invalid or the table cannot be found, the function should return an empty list.
  assert scrape_planets_info('https://en.wikipedia.org/wiki/List_of_gravitationally_rounded_objects_of_the_Solar_System')==[{'name': 'Mercury', 'mass': '0.330', 'distance_from_sun': '57.9'}, {'name': 'Venus', 'mass': '4.87', 'distance_from_sun': '108.2'}, {'name': 'Earth', 'mass': '5.97', 'distance_from_sun': '149.6'}, {'name': 'Mars', 'mass': '0.642', 'distance_from_sun': '227.9'}]
  assert scrape_planets_info('https://invalid.url.com')==[]
  assert scrape_planets_info('https://en.wikipedia.org/wiki/Non_Existent_Page')==[]
output: import requests
  from bs4 import BeautifulSoup
  
  def scrape_planets_info(url):
      try:
          response = requests.get(url)
          response.raise_for_status()
          soup = BeautifulSoup(response.text, 'html.parser')
          table = soup.find('table', {'class': 'wikitable'})
          if not table:
              return []
          rows = table.find_all('tr')
          planets_info = []
          headers = [header.text.strip() for header in rows[0].find_all('th')]
          for row in rows[1:]:
              cells = row.find_all('td')
              if len(cells) >= 3:
                  planet_info = {
                      'name': cells[0].text.strip(),
                      'mass': cells[1].text.strip(),
                      'distance_from_sun': cells[2].text.strip()
                  }
                  planets_info.append(planet_info)
          return planets_info
      except:
          return []