input: Write a function to create a web scraper that extracts specific data from a given website. The function should utilize the Python package BeautifulSoup to parse webpages and extract the required data. BeautifulSoup will allow us to find HTML elements on the webpage using tags and attributes, and the extracted data can be converted into the desired format and stored.
  assert extract_data("https://example.com", 'a', 'href')==['http://example.com/page1', 'http://example.com/page2']
  assert extract_data("https://sample.com", 'img', 'src')==['http://sample.com/image1.jpg', 'http://sample.com/image2.jpg']
  assert extract_data("https://test.com", 'p', None)==['This is paragraph 1.', 'This is paragraph 2.']
  assert extract_data("https://demo.com", 'div', 'class')==['content', 'header', 'footer']
  assert extract_data("", None, None)==[]
output: def extract_data(url, tag, attribute):
      if not url:
          return []
      import requests
      from bs4 import BeautifulSoup
      response = requests.get(url)
      soup = BeautifulSoup(response.text, 'html.parser')
      if attribute:
          elements = soup.find_all(tag)
          return [element.get(attribute) for element in elements if element.get(attribute)]
      else:
          elements = soup.find_all(tag)
          return [element.text for element in elements]