input: Write a python function to count total words from all the linked pages using BeautifulSoup and urllib.
  assert count_total_words('https://www.example.com') == 12345  # replace with the actual expected result
  assert count_total_words('https://www.testpage.com') == 67890  # replace with the actual expected result
  assert count_total_words('https://www.anotherexample.com') == 11223  # replace with the actual expected result
output: def count_total_words(url):
      from bs4 import BeautifulSoup
      import urllib.request
  
      def get_words_from_url(url):
          try:
              response = urllib.request.urlopen(url)
              soup = BeautifulSoup(response, 'html.parser')
              text = soup.get_text()
              words = text.split()
              return words
          except Exception as e:
              print(f"Error fetching {url}: {e}")
              return []
  
      def get_all_links(url):
          try:
              response = urllib.request.urlopen(url)
              soup = BeautifulSoup(response, 'html.parser')
              links = [a['href'] for a in soup.find_all('a', href=True)]
              return links
          except Exception as e:
              print(f"Error fetching links from {url}: {e}")
              return []
  
      main_words = get_words_from_url(url)
      total_words = len(main_words)
      visited_urls = set()
      to_visit_urls = get_all_links(url)
      
      while to_visit_urls:
          next_url = to_visit_urls.pop()
          if next_url not in visited_urls:
              visited_urls.add(next_url)
              next_words = get_words_from_url(next_url)
              total_words += len(next_words)
              new_links = get_all_links(next_url)
              to_visit_urls.extend(new_links)
  
      return total_words