How to use the mechanize.Browser function in mechanize

To help you get started, we’ve selected a few mechanize examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github claudyus / LXC-Web-Panel / tests / browser.py View on Github external
def setUpClass(cls):
        # cleanup
        shutil.copyfile('lwp.db.base', '/tmp/db.sql')
        shutil.rmtree('/tmp/lxc', ignore_errors=True)
        cj = cookielib.LWPCookieJar()
        cls.br = mechanize.Browser()
        cls.br.set_cookiejar(cj)
github dimagi / commcare-hq / loadtest / test_scripts / hq_settings.py View on Github external
def init_browser():
    """Returns an initialized browser and associated cookie jar."""
    br = mechanize.Browser()
    cj = cookielib.LWPCookieJar()
    br.set_cookiejar(cj)

    br.set_handle_equiv(True)
    br.set_handle_gzip(True)
    br.set_handle_redirect(True)
    br.set_handle_referer(True)
    br.set_handle_robots(False)

    br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
    return br
github lehins / django-wepay / django_wepay / tests.py View on Github external
def browser_create():
    browser = mechanize.Browser()
    cj = cookielib.LWPCookieJar()
    browser.set_cookiejar(cj)
    browser.set_handle_equiv(True)
    # browser.set_handle_gzip(True)
    browser.set_handle_redirect(True)
    browser.set_handle_referer(True)
    browser.set_handle_robots(False)
    browser.set_handle_refresh(
        mechanize._http.HTTPRefreshProcessor(), max_time=1)
    # debugging stuff
    #browser.set_debug_redirects(True)
    #browser.set_debug_responses(True)
    #browser.set_debug_http(True)
    browser.addheaders = [
        ('User-Agent' , 
         "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.4 (KHTML, like Gecko)"
github kovidgoyal / calibre / src / libprs500 / manual / make.py View on Github external
def browser():
    opener = mechanize.Browser()
    opener.set_handle_refresh(True)
    opener.set_handle_robots(False)
    opener.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; i686 Linux; en_US; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4')]
    return opener
github gc3pie / gc3pie / gc3apps / gamess / import-gmtkn24.py View on Github external
def __init__(self):
        # initialization
        self._browser = Browser()
        self._browser.set_handle_robots(False)
        self._subsets = self._list_subsets()
github mozilla / security / client / stats / correlate-coverage.py View on Github external
def getCurrentCoverageDirectory(baseURL):
  mech = Browser()
  mech.open(baseURL)
  
  currentLink = None
  
  for link in mech.links():
    # Find the first directory link that is not the parent
    if (link.url.endswith("/") and not link.url.startswith("/")):
      currentLink = link
      break
    
  if currentLink == None:
    mech.close()
    raise "Unable to find current coverage directory"
  
  linkURL = currentLink.base_url + currentLink.url
  mech.close()
github gduverger / coba / src / coba / __init__.py View on Github external
def __init__(self, username, password, otp_type=None, cookiefile=None,
      useragent='COBA/Python (+https://github.com/ericpruitt)'):
        self.username = username
        self.password = password
        self.cookiefile = cookiefile
        self.otp_type = otp_type or EMAIL_VERIFICATION

        self.mech_browser = mech_browser = mechanize.Browser()
        mech_browser.addheaders = [("User-agent", useragent)]
        mech_browser.set_handle_robots(False)

        # There's a refresh with a 760 second delay sent by Chase's server
        # presumably to automatically log out the user, so the refresh handler
        # must be disabled.
        mech_browser.set_handle_refresh(False)

        if cookiefile:
            self.cookiejar = cookiejar = cookielib.LWPCookieJar()

            mech_browser.set_cookiejar(cookiejar)
            self.load_cookies()

        self.browser = zope.testbrowser.browser.Browser(mech_browser=mech_browser)
        self.navigate(self.accountslisturl)