old_contents: #!/usr/bin/env
  import mechanize
  import cookielib
  
  
  def test_agent(url, user_agent):
      browser = mechanize.Browser()
      browser.addheaders = user_agent
      page = browser.open(url)
      source_code = page.read()
      print source_code
  
  
  def print_cookies(url):
      browser = mechanize.Browser()
      cookie_jar = cookielib.LWPCookieJar()
      browser.set_cookiejar(cookie_jar)
      page = browser.open(url)
      for cookie in cookie_jar:
          print cookie
  
  
  user_agent = [('User-agent', 'Mozilla/5.0 (X11; U; Linux 2.4.2-2 i586; en-US; m18) Gecko/20010131 Netscape6/6.01')]
  url = 'http://whatsmyuseragent.com/'
  
  test_agent(url, user_agent)
  print_cookies(url)
  
new_contents: #!/usr/bin/env
  import mechanize
  import cookielib
  import random
  import time
  
  
  class AnonBrowser(mechanize.Browser):
      def __init__(self, proxies=[], user_agents=[]):
          mechanize.Browser.__init__(self)
          self.set_handle_robots(False)
          self.proxies = proxies
          self.user_agents = user_agents + ['Mozilla/4.0',
                                            'FireFox/6.01',
                                            'ExactSearch',
                                            'Nokia7110/1.0']
          self.cookie_jar = cookielib.LWPCookieJar()
          self.set_cookiejar(self.cookie_jar)
          self.anonymize()
  
      def clear_cookies(self):
          self.cookie_jar = cookielib.LWPCookieJar()
          self.set_cookiejar(self.cookie_jar)
  
      def change_user_agent(self):
          index = random.randrange(0, len(self.user_agents))
          self.addheaders = [('User-agent', (self.user_agents[index]))]
  
      def change_proxy(self):
          if self.proxies:
              index = random.randrange(0, len(self.proxies))
              self.set_proxies({'http': self.proxies[index]})
  
      def anonymize(self, sleep=False):
          self.clear_cookies()
          self.change_user_agent()
          self.change_proxy()
          if sleep:
              time.sleep(60)
  
  
  def test_agent(url, user_agent):
      browser = mechanize.Browser()
      browser.addheaders = user_agent
      page = browser.open(url)
      source_code = page.read()
      print source_code
  
  
  def print_cookies(url):
      browser = mechanize.Browser()
      cookie_jar = cookielib.LWPCookieJar()
      browser.set_cookiejar(cookie_jar)
      page = browser.open(url)
      for cookie in cookie_jar:
          print cookie
  
  
  user_agent = [('User-agent', 'Mozilla/5.0 (X11; U; Linux 2.4.2-2 i586; en-US; m18) Gecko/20010131 Netscape6/6.01')]
  url = 'http://whatsmyuseragent.com/'
  
  test_agent(url, user_agent)
  print_cookies(url)
  
subject: Add AnonBrowser class