def get_browser(self): """ Each FAUrl object stores it's own browser instance. On the first call it is created and if the username and password is set it will authenticate you. :return: mechanize.Browser instance. :raise: FAiler.FAError if FA is down. Time to F5! :raise: FAiler.FAAuth Your username and password failed """ if self._br is None: br = Browser() br.set_handle_robots(False) br.set_handle_redirect(True) br.set_handle_referer(True) br.set_handle_equiv(True) br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')] if self._username is not None and self._password is not None: loginPage = 'https://www.furaffinity.net/login' try: br.open(loginPage) except urllib2.HTTPError: raise FAError("FA's down, F5 time.") br.form = br.global_form() br.form['name'] = self._username br.form['pass'] = self._password br.form.method = 'POST' br.submit() if br.geturl() == loginPage + '/?msg=1': raise FAAuth('Username & Password Incorrect') self._br = br return self._br