当前位置: 首页>>代码示例>>Python>>正文


Python Browser.set_debug_responses方法代码示例

本文整理汇总了Python中mechanize.Browser.set_debug_responses方法的典型用法代码示例。如果您正苦于以下问题:Python Browser.set_debug_responses方法的具体用法?Python Browser.set_debug_responses怎么用?Python Browser.set_debug_responses使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mechanize.Browser的用法示例。


在下文中一共展示了Browser.set_debug_responses方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_mechanized_browser

# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import set_debug_responses [as 别名]
 def get_mechanized_browser(self, url):
     mech = Browser()
     mech.set_handle_robots(False)
     mech.set_debug_redirects(self.debug)
     mech.set_debug_responses(self.debug)
     mech.set_debug_http(self.debug)
     mech.open(url)
     assert mech.viewing_html()
     return mech
开发者ID:scantron,项目名称:pooled,代码行数:11,代码来源:stats_update.py

示例2: create_browser

# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import set_debug_responses [as 别名]
def create_browser(debug=False):
    browser = Browser(factory=mechanize.RobustFactory())
    if debug:
        # Maybe enable this if you want even more spam...
        # logger = logging.getLogger("mechanize")
        # logger.addHandler(logging.StreamHandler(sys.stdout))
        # logger.setLevel(logging.DEBUG)
        browser.set_debug_http(True)
        browser.set_debug_responses(True)
        browser.set_debug_redirects(True)
    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.addheaders = HEADERS
    return browser
开发者ID:kevinwu06,项目名称:scraping_stuff,代码行数:19,代码来源:headless_browser.py

示例3: set_debug_responses

# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import set_debug_responses [as 别名]
 def set_debug_responses(self, *args, **kwargs):
     B.set_debug_responses(self, *args, **kwargs)
     self._clone_actions['set_debug_responses'] = ('set_debug_responses',
             args, kwargs)
开发者ID:JapaChin,项目名称:calibre,代码行数:6,代码来源:browser.py

示例4: Browser

# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import set_debug_responses [as 别名]
import re

from mechanize import Browser

br = Browser()
br.set_debug_http(True)
br.set_debug_responses(True)
br.set_debug_redirects(True)



I = 0
def save(func, *args, **kwargs):
    global I
    resp = func(*args, **kwargs)
    page = resp.read()
    filename = 'page%s.html' % I
    I += 1
    with open(filename, 'w') as f:
        f.write(page)
    return page

def login():
    save(br.open, 'https://retail.santander.co.uk/LOGSUK_NS_ENS/BtoChannelDriver.ssobto?dse_operationName=LOGON')
    br.select_form('formCustomerID_1')
    br['infoLDAP_E.customerID'] = '7767598534'
    challenge = save(br.submit)
    br.select_form(nr=0)
    if 'Place of Birth' in challenge:
        answer = 'Stranraer'
    else:
开发者ID:mallison,项目名称:money,代码行数:33,代码来源:santander.py

示例5: LconnectScraper

# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import set_debug_responses [as 别名]
class LconnectScraper(ClassDataScraper):
    LCONNECT_URL = 'http://leopardweb.wit.edu/'
    USERAGENT = 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.1) ' \
                + 'Gecko/20100122 firefox/3.6.1'

    def __init__(self):
        # Create a cookie jar and a browser
        self._cookieJar = LWPCookieJar()
        self._browser = Browser()
        self._browser.set_cookiejar(self._cookieJar)

        # Set Browser options
        self._browser.set_handle_equiv(True)
        self._browser.set_handle_gzip(True)
        self._browser.set_handle_redirect(True)
        self._browser.set_handle_referer(True)
        self._browser.set_handle_robots(False)
        self._browser.set_handle_refresh(_http.HTTPRefreshProcessor(),
                                         max_time=1)
        self._browser.addheaders = [('User-agent', LconnectScraper.USERAGENT)]

        # Debugging
        self._browser.set_debug_http(True)
        self._browser.set_debug_redirects(True)
        self._browser.set_debug_responses(True)

    def getName(self):
        return "Lconnect Scraper"

    def connect(self):
        """
        Attempts to connect to the data source
        """
        try:
            # Try to open a connection. 8 Second timeout
            self._browser.open(LconnectScraper.LCONNECT_URL, timeout=8)
            return True
        except URLError:
            return False

    def disconnect(self):
        """
        Disconnects from the data source
        """

        self._browser.close()

    def requiresAuthentication(self):
        """
        Returns whether or not the scraper requires authentication information
        """

        return True

    def authenticate(self, username, password):
        """
        Attempts to authenticate the scraper using username and password
        """

        # If we're on the sign in page, try to sign in
        if self._browser.title() == 'Sign In':
            for form in self._browser.forms():
                if form.name is None:
                    self._browser.form = list(self._browser.forms())[0]
                    self._browser['username'] = username
                    self._browser['password'] = password

                    self._browser.submit()

        # If the browser's title is 'Main Menu',
        # we've either successfully logged in, or we were already
        if self._browser.title() == 'Main Menu':
            return True
        else:
            return False

    def getClassData(self):
        """
        Returns a list of ClassData objects
        """

        return []
开发者ID:mitranog,项目名称:lana,代码行数:84,代码来源:LconnectScraper.py

示例6: login

# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import set_debug_responses [as 别名]
def login():

    creds = get_credentials()
    if not creds:
        return None

    b = Browser()
    b.set_handle_robots(False)
    b.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'),
        ('Connection', 'keep-alive'),
        ('Cache-Control', 'max-age=0'),
        ('Accept-Encoding', 'gzip, deflate, br')
    ]

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

    # Follows refresh 0 but not hangs on refresh > 0
    b.set_handle_refresh(_http.HTTPRefreshProcessor(), max_time=1)

    # Want debugging messages?
    # b.set_debug_http(True)
    b.set_debug_redirects(True)
    b.set_debug_responses(True)
    print 'Opening main page...'
    b.open('http://www.nab.com.au')
    print 'OK'

    print 'Opening login redir page...'
    b.open('http://www.nab.com.au/cgi-bin/ib/301_start.pl?browser=correct')
    print 'OK'

    print 'Opening real login page...'
    b.open('https://ib.nab.com.au/nabib/index.jsp')
    print 'OK'

    b.select_form(nr=0)
    try:
        webKeyCtrl = b.form.find_control(id='webKey')
        webAlphaCtrl = b.form.find_control(id='webAlpha')
    except ControlNotFoundError:
        print 'Cannot find necessary login controls, quitting'
        return

    webKey = webKeyCtrl.value
    webAlpha = webAlphaCtrl.value
    newPassword = make_password(creds[1], webKey, webAlpha)

    usernameCtrl = b.form.find_control(name='userid')
    passwordCtrl = b.form.find_control(name='encoded-password')
    passwordCtrl.readonly = False
    usernameCtrl.value = creds[0]
    passwordCtrl.value = newPassword

    rawPassword = b.form.find_control(name='password')
    rawPassword.value = ''

    b_data = b.form.find_control(name='browserData')
    b_data.readonly = False
    b_data.value = '1496488636702;z=-600*-600;s=1440x900x24;l=en-GB;p=MacIntel;h=1Z3uS;i=33;j=117;k=16;c=d3d3Lm5hYi5jb20uYXUvc3RhdGljL0lCL2xvZ2luQmFubmVyLw;n=bG9naW5Gb3Jt,bG9naW5UaXBz;e=Y3ZpZXcz;b=1JE4yQ,24uNEg,2wDBVE;a=1GeUEa,1TaPsP,1ZO-16,1rEqxh,2.jbKy,21b2P5,2Jrfu6,2LmSef,2TqVCf,2Ubrnm,2dgqqB,3MkcJZ,JIGdn,eqyBa,lTM8m;o=Y29uc29sZQ,Y2hyb21l,YW5ndWxhcg,YXBpTG9nb3V0QXBw,Z2V0QnJvd3Nlcg,alF1ZXJ5MTEwMjA4MzYwNzIxMDQ4NTY0MjY0;t=fo4f0ot8-600.j3h6ekzf.877;d=YWNz,Ym9keWNvbnRhaW5lcg,Ym9keWNvbnRhaW5lcl9pbnNpZGU,YmFubmVy,ZXJyb3JNZXNzYWdl,ZXJyb3JOdW1iZXI,Zm9vdGVyX2xvZ2lu,ZmFuY3ktYmctZQ,ZmFuY3ktYmctbg,ZmFuY3ktYmctbmU,ZmFuY3ktYmctbnc,ZmFuY3ktYmctc2U,ZmFuY3ktYmctc3c,ZmFuY3ktYmctcw,ZmFuY3ktYmctdw,ZmFuY3lib3gtY2xvc2U,ZmFuY3lib3gtaW5uZXI,ZmFuY3lib3gtb3V0ZXI,ZmFuY3lib3gtb3ZlcmxheQ,ZmFuY3lib3gtbG9hZGluZw,ZmFuY3lib3gtbGVmdA,ZmFuY3lib3gtbGVmdC1pY28,ZmFuY3lib3gtcmlnaHQ,ZmFuY3lib3gtcmlnaHQtaWNv,ZmFuY3lib3gtd3JhcA,ZmFuY3lib3gtdG1w,aGVhZGVy,aWItdXNlci10ZXh0,bG9naW5Gb3Jt,bGlua3Mtc29jaWFsLW1lZGlh,bWFpblBhZ2U;u=ZHVtbXk,ZW5jb2RlZC1wYXNzd29yZA,d2ViQWxwaGE,d2ViS2V5;v=bmVlZC1oZWxw;x=1IVClf,1KxWAP,1SURBl,1Wl6jj,1vhE2s,1vstXM,1wlzQT,1yYwT1,2-PmTs,2APt-x,2FOxw2,2Lnxl,2ceYJE,2feZ0x,2g4LgQ,2h079f,2oK-0A,2ueFc7,34liSK,39CTWT,3GxyfT,3T6P3H,3XvqP.,3kcnCG,3ktPLw,3l39dK,660SR,68npD,8Vcav,JOS8B,cTezC,dwOmq,ix9Ek,s-ZAp;q=ZnJhdWQ;w=428866'

    b.form.new_control('text', 'login', {'value': ''})
    b.form.fixup()
    b['login'] = 'Login'

    print('Logging in...')
    b.submit()

    if not check_url(b, logged_in_urls):
        print('Error logging in.')
        return None

    print('OK')
    return b
开发者ID:ArtS,项目名称:nab-export,代码行数:80,代码来源:browser.py

示例7: login

# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import set_debug_responses [as 别名]
def login():

    creds = get_credentials()
    if not creds:
        return None

    b = Browser()
    b.set_handle_robots(False)
    b.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')]

    b.set_handle_equiv(True)
    #b.set_handle_gzip(True)
    b.set_handle_redirect(True)
    b.set_handle_referer(True)
    b.set_handle_robots(False)

    # Follows refresh 0 but not hangs on refresh > 0
    b.set_handle_refresh(_http.HTTPRefreshProcessor(), max_time=1)

    # Want debugging messages?
    #b.set_debug_http(True)
    b.set_debug_redirects(True)
    b.set_debug_responses(True)


    print 'Opening main page...'
    b.open('http://www.nab.com.au')
    print 'OK'

    print 'Opening login redir page...'
    b.open('http://www.nab.com.au/cgi-bin/ib/301_start.pl?browser=correct')
    print 'OK'

    print 'Opening real login page...'
    b.open('https://ib.nab.com.au/nabib/index.jsp')
    print 'OK'

    b.select_form(nr=0)
    try:
        webKeyCtrl = b.form.find_control(id='webKey')
        webAlphaCtrl = b.form.find_control(id='webAlpha')
    except ControlNotFoundError:
        print 'Cannot find necessary login controls, quitting'
        return

    webKey = webKeyCtrl.value
    webAlpha = webAlphaCtrl.value
    newPassword = make_password(creds[1], webKey, webAlpha)

    usernameCtrl = b.form.find_control(name='userid')
    passwordCtrl = b.form.find_control(name='password')
    usernameCtrl.value = creds[0]
    passwordCtrl.value = newPassword

    b_data = b.form.find_control(name='browserData')
    b_data.readonly = False
    b_data.value = '1332067415674;z=-660*-600;s=1440x900x24;h=325b2e41;l=en-US;p=MacIntel;i=0;j=7;k=0;c=81d6c46c:,799e53ad:,f67180ac:,c801b011:,9ed81ce8:,68bab54a:,3db529ef,97362cfc;'

    b.form.new_control('text', 'hidden', {'name': 'login', 'value': 'Login'})

    print('Logging in...')
    b.submit()

    if not check_url(b, logged_in_urls):
        print('Error logging in.')
        return None

    print('OK')
    return b
开发者ID:tf198,项目名称:nab-export,代码行数:71,代码来源:browser.py

示例8: Browser

# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import set_debug_responses [as 别名]
url = sys.argv[1]
print "Scanning: %s " % url
print

mech = Browser()
cj = LWPCookieJar()
mech.set_cookiejar(cj)
mech.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')]
mech.set_handle_robots(False)
mech.set_handle_equiv(True)
mech.set_handle_gzip(True)
mech.set_handle_referer(True)
mech.set_debug_http(True)
mech.set_debug_redirects(True)
mech.set_debug_responses(True)
page = mech.open(url)
html = page.read()
soup = BeautifulSoup(html)
 
# Extract all anchors on the page that include the string ".mp3"
anchors = soup.findAll(attrs={'href' : re.compile(".mp3")})
for a in anchors:
    mp3link = a['href'] # Get the value of the href, not the whole tag/container!
    
    # To get an output filename, split the URL on slashes and grab the last array item
    urlfrags = mp3link.split('/')
    save_as = urlfrags[len(urlfrags)-1] # Resolves to e.g. urlfrags[4]
    print mp3link
    print "Saving: %s" % save_as
    print
开发者ID:atmlvs,项目名称:MyLib,代码行数:32,代码来源:scrapemp3s.py

示例9: __init__

# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import set_debug_responses [as 别名]
 def __init__(self, default_encoding="latin-1"):
     Browser.__init__(self)
     self.last_call_latency = 0
     Browser.set_debug_responses(self, True)
     Browser.set_debug_redirects(self, True)
开发者ID:mrmaple,项目名称:open_qon,代码行数:7,代码来源:test_http_loadtesting.py

示例10: Mbank

# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import set_debug_responses [as 别名]
class Mbank(object):
    """
    Glowna klasa realizujaca akcje logowania, przejscia na odpowiedni
    formularz i wykonywania pozadanych akcji na stronach panelu klienta
    mbanku.
    """
    def __init__(self, id, password, bank_number=None):
        self.id = id
        self.password = password
        self.bank_number = bank_number.replace(' ', '')
        self.url = 'https://www.mbank.com.pl'
        self.form_name = 'MainForm'

        self.br = Browser()
        # Ustawienie naglowkow (szczegolnie istotny Accept-Encoding)
        # bez ktorego nie pobraloby dane w postaci CSV/HTML.
        self.br.addheaders = [
            ('User-Agent', 'Mozilla/5.0 (X11; U; Linux x86_64; ' \
             'pl-PL; rv:1.9.2.6) Gecko/20100628 Ubuntu/10.04 ' \
             '(lucid) Firefox/3.6.6'),
            ('Accept-Encoding', 'gzip,deflate'),
            ('Referer', 'https://online.mbank.pl/pl/Login'),
        ]

        # debugi
        if DEBUG:
            self.br.set_debug_redirects(True)
            self.br.set_debug_responses(True)
            self.br.set_debug_http(True)

    def login(self):
        """
        Metoda realizujaca logowanie sie do panelu klienta mbanku.
        """
        now = datetime.datetime.now()
        formated_now = now.strftime('%a, %d %b %Y, %X').lower()
        self.br.open(self.url)
        self.br.select_form(name=self.form_name)
        self.br.form.set_all_readonly(False)
        self.br.form.set_value(name='customer', value=self.id)
        self.br.form.set_value(name='password', value=self.password)
        self.br.form.set_value(name='localDT', value=formated_now)
        return self.br.submit()

    def select_account(self, bank_number):
        """
        Wybiera konto bankowe na podstawie @bank_number i wysyla POST
        z odpowiednimi parametrami dla danego konta.
        """
        self.br.open('https://www.mbank.com.pl/accounts_list.aspx')

        for l in self.br.links():
            if l.text.replace(' ', '').find(bank_number) > -1:
                break

        # Znajdz atrybut onclick dla taga <a> z numerem konta bankowego.
        for a in l.attrs:
            if a[0] == 'onclick':
                onclick = a[1].split("'")
                break

        # Wszystkie ponizsze dane pobierane sa z atrybutu onclick,
        # w ktorym to uruchamiana jest funkcja JS doSubmit().

        # Adres gdzie bedziemy slac dane.
        addr = onclick[1]
        # Metoda wysylania (POST)
        method = onclick[5]
        # Parametry
        params = onclick[7]


        self.br.select_form(name=self.form_name)
        self.br.form.action = '%s%s' % (self.url, addr)
        self.br.form.method = method
        # Aktywuj inputa __PARAMETERS (ma ustawiony status readonly)
        self.br.form.set_all_readonly(False)
        # Przypisz parametry
        self.br.form.set_value(name='__PARAMETERS', value=params)
        return self.br.submit()

    def history_form(self):
        """
        Przejscie na formularz historii transakcji.
        """
        self.br.select_form(name=self.form_name)
        self.br.form.action = '%s%s' % (self.url, '/account_oper_list.aspx')
        self.br.form.method = 'POST'
        return self.br.submit()

    def _get_history(self, type, last_day=False):
        """
        Metoda ustawiajaca odpowiednie parametry na formularzu historii
        transakcji i wysylajaca go.
        """
        self.br.select_form(name=self.form_name)
        # exportuj dane
        self.br.form.find_control("export_oper_history_check").items[0].selected = True
        # ustawienie selecta z typem danych (domyslnie HTML)
        self.br.form.set_value(name='export_oper_history_format', value=[type])
#.........这里部分代码省略.........
开发者ID:pbylina,项目名称:python-mbank,代码行数:103,代码来源:mbank.py

示例11: PinboardAccount

# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import set_debug_responses [as 别名]
class PinboardAccount(object):
    __allposts = 0
    __postschanged = 0

    # Time of last request so that the one second limit can be enforced.
    __lastrequest = None
    
    def __init__(self, username, password,refid):
            self.br = Browser()
            self.username=username
            self.password = password
            self.refid = refid
            self.br.set_handle_robots(False)
            
            # Browser options
            self.br.set_handle_equiv(True)
            self.br.set_handle_redirect(True)
            self.br.set_handle_referer(True)
            self.br.set_handle_robots(False)

            self.br.set_debug_http(True)
            self.br.set_debug_redirects(True)
            self.br.set_debug_responses(True)

            # Follows refresh 0 but not hangs on refresh > 0
            self.br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)

            self.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')]
            page = self.br.open(PINBOARD_URL)
            form = self.br.forms().next()  # the login form is unnamed...
            if _debug:
                print form.action        # prints form
            self.br.select_form(nr=0)
            self.br["email"]=username
            self.br["password"]=password
            resp  = self.br.submit()
            con = resp.read()
            matchExpr =  "csrfmiddlewaretoken' value='(.*[^']?)'"                 
            self.csrf=re.findall( matchExpr , con )[0]
            print "CSRF is %s "%self.csrf
            conn=self.br.open("http://pinterest.com/%s/"%refid).read()
                     
    @retry( Exception)
    def createaPin(self,  boardID , desc ,urlSite,  taglist): 
            print "Post data  is  %s  %s  %s  %s "%(boardID  , desc ,  urlSite , taglist)
            time.sleep(6)
            self.br.open("http://pinterest.com/%s/pins/"%self.refid)
            f=urllib.urlretrieve(urlSite)[0]
            postData = {'board': boardID,
                                         'details': desc   ,
                                         'link' : urlSite ,
                                         'img_url' : urlSite ,
                                         'tags' : taglist ,
                                         'replies' : '' ,
                                         'buyable' : '' ,
                                         'img' : open( f , "rb") , 
                                        'csrfmiddlewaretoken' : self.csrf}
            request = self.br.open("http://pinterest.com/pin/create/", urllib.urlencode(postData))
            content = json.loads(request.read()).get("url")
            pinID = string.replace( content , "/pin/" , "" ).replace("/" , "")
            return pinID

    def getAllBoardsForUser(self , refName):
            time.sleep(1)
            resp = self.br.open("http://pinterest.com/%s/"%refName)
            con = resp.read()
            jsonBoard="""var myboards =(.*?[^]]?)]"""
            m =  re.findAll( re.compile(jsonBoard), con )
            print  m
            content = json.loads(request.read()).get("url")
            pinID = string.replace( content , "/pin/" , "" ).replace("/" , "")
            return pinID
        

    def doAllGood(self ,userName , password   , comment, count , boardListStr):
        os.system("/Users/Mark/apache-jmeter-2.6/bin/jmeter.sh -JuserName=%s -Jpassword=%s -Jnthreads=%s   -JrefName=%s -JhostName=pinterest.com  -JtargetBoardList=%s -n  -t  doAllGood.jmx  " %(userName , password,   count , self.refid, boardListStr  ))
        #os.system("\"D:\\java\\apache-jmeter-2.6\\bin\\jmeter.bat\" -JuserName=%s -Jpassword=%s -Jnthreads=%s -JrefName=%s -JhostName=pinterest.com   -JtargetBoardList=%s -n  -t  doAllGood.jmx  " %(userName , password,   count , self.refid, boardListStr  ))
             
    def createBoard(self, csvFile):
          boardList = self.getBoardListForUser()
          print  boardList
          count  =  len([   x.strip()    for     x in   file(csvFile).readlines()  ])
          print count 
          os.system("\"D:\\java\\apache-jmeter-2.6\\bin\\jmeter.bat\" -JuserName=%s -Jpassword=%s -Jnthreads=%s -JrefName=%s -JhostName=pinterest.com  -n  -t  doCreateBoard.jmx  " %(self.username , self.password, count  ,self.refid  ))
    
    def getBoardListForUser(self ):
          urlBoard  =   self.br.open("http://pinterest.com/%s"%self.refid)
          #if re.compile(l.url).match("http://pinterest.com/%s/(.*?[^/]?)/"%self.refid)
          self.listBoards = [  l.text  for  l   in  self.br.links()  ]
          return  self.listBoards
开发者ID:pdam,项目名称:pinb,代码行数:92,代码来源:pinboard.py

示例12: Mbank

# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import set_debug_responses [as 别名]
class Mbank(object):
    """
    Glowna klasa realizujaca akcje logowania, przejscia na odpowiedni
    formularz i wykonywania pozadanych akcji na stronach panelu klienta
    mbanku.
    """

    def __init__(self, id, password, bank_number=None):
        self.id = id
        self.password = password
        self.bank_number = bank_number.replace(" ", "")
        self.url = "https://www.mbank.com.pl"
        self.form_name = "MainForm"

        self.br = Browser()
        # Ustawienie naglowkow (szczegolnie istotny Accept-Encoding)
        # bez ktorego nie pobraloby dane w postaci CSV/HTML.
        self.br.addheaders = [
            (
                "User-Agent",
                "Mozilla/5.0 (X11; U; Linux x86_64; "
                "pl-PL; rv:1.9.2.6) Gecko/20100628 Ubuntu/10.04 "
                "(lucid) Firefox/3.6.6",
            ),
            ("Accept-Encoding", "gzip,deflate"),
        ]

        # debugi
        if DEBUG:
            self.br.set_debug_redirects(True)
            self.br.set_debug_responses(True)
            self.br.set_debug_http(True)

    def login(self):
        """
        Metoda realizujaca logowanie sie do panelu klienta mbanku.
        """
        now = datetime.datetime.now()
        formated_now = now.strftime("%a, %d %b %Y, %X").lower()
        self.br.open(self.url)
        self.br.select_form(name=self.form_name)
        self.br.form.set_all_readonly(False)
        self.br.form.set_value(name="customer", value=self.id)
        self.br.form.set_value(name="password", value=self.password)
        self.br.form.set_value(name="localDT", value=formated_now)
        return self.br.submit()

    def select_account(self, bank_number):
        """
        Wybiera konto bankowe na podstawie @bank_number i wysyla POST
        z odpowiednimi parametrami dla danego konta.
        """
        self.br.open("https://www.mbank.com.pl/accounts_list.aspx")

        for l in self.br.links():
            if l.text.replace(" ", "").find(bank_number) > -1:
                break

        # Znajdz atrybut onclick dla taga <a> z numerem konta bankowego.
        for a in l.attrs:
            if a[0] == "onclick":
                onclick = a[1].split("'")
                break

        # Wszystkie ponizsze dane pobierane sa z atrybutu onclick,
        # w ktorym to uruchamiana jest funkcja JS doSubmit().

        # Adres gdzie bedziemy slac dane.
        addr = onclick[1]
        # Metoda wysylania (POST)
        method = onclick[5]
        # Parametry
        params = onclick[7]

        self.br.select_form(name=self.form_name)
        self.br.form.action = "%s%s" % (self.url, addr)
        self.br.form.method = method
        # Aktywuj inputa __PARAMETERS (ma ustawiony status readonly)
        self.br.form.set_all_readonly(False)
        # Przypisz parametry
        self.br.form.set_value(name="__PARAMETERS", value=params)
        return self.br.submit()

    def history_form(self):
        """
        Przejscie na formularz historii transakcji.
        """
        self.br.select_form(name=self.form_name)
        self.br.form.action = "%s%s" % (self.url, "/account_oper_list.aspx")
        self.br.form.method = "POST"
        return self.br.submit()

    def _get_history(self, type, last_day=False):
        """
        Metoda ustawiajaca odpowiednie parametry na formularzu historii
        transakcji i wysylajaca go.
        """
        self.br.select_form(name=self.form_name)
        # exportuj dane
        self.br.form.find_control("export_oper_history_check").items[0].selected = True
#.........这里部分代码省略.........
开发者ID:pb-it,项目名称:python-mbank,代码行数:103,代码来源:mbank.py


注:本文中的mechanize.Browser.set_debug_responses方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。