code: def links(args):
      
      p = OptionParser(links.__doc__)
      p.add_option("--img", default=False, action="store_true",
                   help="Extract <img> tags [default: %default]")
      opts, args = p.parse_args(args)
  
      if len(args) != 1:
          sys.exit(not p.print_help())
  
      url, = args
      img = opts.img
  
      htmlfile = download(url)
      page = open(htmlfile).read()
      soup = BeautifulSoup(page)
  
      tag = 'img' if img else 'a'
      src = 'src' if img else 'href'
      aa = soup.findAll(tag)
      for a in aa:
          link = a.get(src)
          link = urljoin(url, link)
          print(link)
docs: %prog links url
  
      Extract all the links "<a href=''>" from web page.