input: Write a function to implement a web crawler in Python that starts from a given URL and extracts all external links from the page. The crawler should visit each page and continue until it has explored all accessible links from the initial page. If the input URL is invalid or cannot be accessed, return an empty list.
  def crawl(url):
   visited = set()
   queue = [url]
   all_links = []
   
   while queue:
   curr = queue.pop(0)
   visited.add(curr) 
   response = requests.get(curr)
   
   if response.ok:
   soup = BeautifulSoup(response.text, 'html.parser')
  
  # scrape the page here 
  
  # find all the links
   links = soup.find_all('a', href=re.compile('^http')) 
   
   for link in links:
   all_links.append(link['href'])
   if link['href'] not in visited:
   queue.append(link['href'])
   
   return all_links
  
  assert crawl('http://example.com') == []
  assert crawl('http://invalidurl.xyz') == []
  assert crawl('http://example.com') == ['http://example.com/link1', 'http://example.com/link2']
output: 
  def crawl(url):
      visited = set()
      queue = [url]
      all_links = []
      
      while queue:
          curr = queue.pop(0)
          visited.add(curr) 
          try:
              response = requests.get(curr)
              if response.ok:
                  soup = BeautifulSoup(response.text, 'html.parser')
                  links = soup.find_all('a', href=re.compile('^http')) 
                  for link in links:
                      all_links.append(link['href'])
                      if link['href'] not in visited:
                          queue.append(link['href'])
          except:
              pass
      
      return all_links
  