• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python commands.get_browser函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中twill.commands.get_browser函数的典型用法代码示例。如果您正苦于以下问题:Python get_browser函数的具体用法?Python get_browser怎么用?Python get_browser使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: visit_loginurl

def visit_loginurl (aggregate):
    """Check for a login URL and visit it."""
    config = aggregate.config
    url = config["loginurl"]
    if not url:
        return
    if not fileutil.has_module("twill"):
        msg = strformat.format_feature_warning(module=u'twill',
            feature=u'login URL visit',
            url=u'http://twill.idyll.org/')
        log.warn(LOG_CHECK, msg)
        return
    from twill import commands as tc
    log.debug(LOG_CHECK, u"Visiting login URL %s", url)
    configure_twill(tc)
    tc.go(url)
    if tc.get_browser().get_code() != 200:
        log.warn(LOG_CHECK, _("Error visiting login URL %(url)s.") % \
          {"url": url})
        return
    submit_login_form(config, url, tc)
    if tc.get_browser().get_code() != 200:
        log.warn(LOG_CHECK, _("Error posting form at login URL %(url)s.") % \
          {"url": url})
        return
    #XXX store_cookies(tc.get_browser().cj, aggregate.cookies, url)
    resulturl = tc.get_browser().get_url()
    log.debug(LOG_CHECK, u"URL after POST is %s" % resulturl)
    # add result URL to check list
    from ..checker import get_url_from
    aggregate.urlqueue.put(get_url_from(resulturl, 0, aggregate))
开发者ID:bootstraponline,项目名称:linkchecker,代码行数:31,代码来源:__init__.py


示例2: require

def require(what):
    """
    >> require <what>

    After each page is loaded, require that 'what' be satisfied.  'what'
    can be:
      * 'success' -- HTTP return code is 200
      * 'links_ok' -- all of the links on the page load OK (see 'check_links'
                      extension module)
    """
    global _requirements
    from twill import commands

    #
    # install the post-load hook function.
    #

    if _require_post_load_hook not in commands.get_browser()._post_load_hooks:
        if DEBUG:
            print>>commands.OUT, 'INSTALLING POST-LOAD HOOK'
        commands.get_browser()._post_load_hooks.append(_require_post_load_hook)

    #
    # add the requirement.
    #

    if what not in _requirements:
        if DEBUG:
            print>>commands.OUT, 'Adding requirement', what
        _requirements.append(what)
开发者ID:zenoss,项目名称:twill,代码行数:30,代码来源:require.py


示例3: download_project_export

def download_project_export():
    url = get_browser().get_url()
    assert url.endswith(".zip")
    zipcontents = get_browser().get_html()
    output = StringIO()
    output.write(zipcontents)
    z = zipfile.ZipFile(output, "r")
    name = url.split("/")[-1]
    globals, locals = get_twill_glocals()
    globals["__project_export__"] = (z, name)
开发者ID:socialplanning,项目名称:flunc,代码行数:10,代码来源:zope_run_cat_queue.py


示例4: fetch_disease_model

def fetch_disease_model(id):
    from twill import set_output

    set_output(open("/dev/null", "w"))

    dismod_server_login()

    twc.go(DISMOD_DOWNLOAD_URL % id)
    result_json = twc.show()
    twc.get_browser()._browser._response.close()  # end the connection, so that apache doesn't get upset

    dm = DiseaseJson(result_json)
    return dm
开发者ID:flaxter,项目名称:gbd,代码行数:13,代码来源:disease_json.py


示例5: no_require

def no_require():
    """
    >> no_require

    Remove all post-load requirements.
    """
    from twill import commands
    
    l = commands.get_browser()._post_load_hooks
    l = [ fn for fn in l if fn != _require_post_load_hook ]
    commands.get_browser()._post_load_hooks = l

    global _requirements
    _requirements = []
开发者ID:zenoss,项目名称:twill,代码行数:14,代码来源:require.py


示例6: wyloguj

def wyloguj(commands):
    
    forms = commands.showforms()                            # Pobranie formularzy
    naszForm = None                                         # Zmienna do ktorej zapiszemy znaleziony przez nas form
    for form in forms:                                      # Petla po formualrzach
        if form.action == 'https://edukacja.pwr.wroc.pl/EdukacjaWeb/logOutUser.do':     # Jesli akcja danego formularza przenosi do szczegolow
            naszForm = form                                 # To zapisujemy znaleziony formularz
    
    #print(naszForm)                                         # DO USUNIECIA! Wypisuje znaleziony formularz
    
    ctrl = naszForm.controls                                                # pobieram ze znalezionego formularza wszystkie kontrolki
    for ct in ctrl:
        if ct.type == 'submit':                                             # szukam wsrod niej tej co ma typ submit
            commands.get_browser().clicked(naszForm, ct.attrs['name'])      # klikam na ten przycisk
            commands.get_browser().submit()
开发者ID:marta90,项目名称:Projekt,代码行数:15,代码来源:views.py


示例7: _run_xpath

def _run_xpath(xpath):
    _, twill_locals = get_twill_glocals()
    browser = get_browser()
    html = browser.get_html()
    tree = lxml.html.document_fromstring(html)

    try:
        results = tree.xpath(xpath)
    except XPathEvalError:
        err_msg = "Invalid xpath expression: '%s'" % xpath
        log_error(err_msg)
        raise TwillException(err_msg)

    # XXX we aggregate all the values together and warn when there is more than
    # one result
    if results:
        if len(results) > 1:
            log_warn("xpath '%s' found multiple results: using all of them" % xpath)
        result = "\n".join(lxml.html.tostring(r) for r in results)
    else:
        log_error("xpath '%s' found no results")
        result = ""
    # in case we want to cache it at some point
    twill_locals["__xpath_result__"] = result
    twill_locals["__xpath_expr__"] = xpath
    return result
开发者ID:socialplanning,项目名称:flunc,代码行数:26,代码来源:xpath.py


示例8: test_tidy

def test_tidy():
    """
    test parsing of tidy-processed HTML.
    """
    b = commands.get_browser()

    commands.config('use_tidy', '1')
    commands.config('use_BeautifulSoup', '0')
    commands.config('allow_parse_errors', '0')

    commands.go(url)

    ###
    
    commands.go('/tidy_fixable_html')

    forms = [ i for i in b._browser.forms() ]
    assert len(forms) == 1, \
	"you must have 'tidy' installed for this test to pass"

    ###

    commands.go('/BS_fixable_html')
    forms = [ i for i in b._browser.forms() ]
    assert len(forms) == 1, \
           "there should be one mangled form on this page"
开发者ID:t0ster,项目名称:twill,代码行数:26,代码来源:test-broken-html.py


示例9: test_BeautifulSoup

def test_BeautifulSoup():
    """
    test parsing of BS-processed HTML.
    """
    b = commands.get_browser()

    commands.config('use_tidy', '0')
    commands.config('use_BeautifulSoup', '1')
    commands.config('allow_parse_errors', '0')

    commands.go(url)

    ###
    
    commands.go('/tidy_fixable_html')

    forms = [ i for i in b._browser.forms() ]
    assert len(forms) == 0, \
           "there should be no correct forms on this page"

    ###

    commands.go('/BS_fixable_html')
    forms = [ i for i in b._browser.forms() ]
    assert len(forms) == 1, \
           "there should be one mangled form on this page"
开发者ID:t0ster,项目名称:twill,代码行数:26,代码来源:test-broken-html.py


示例10: test_raw

def test_raw():
    """
    test parsing of raw, unfixed HTML.
    """
    b = commands.get_browser()

    commands.config('use_tidy', '0')
    commands.config('use_BeautifulSoup', '0')
    commands.config('allow_parse_errors', '0')

    commands.go(url)

    ###
    # Apparently, mechanize is more tolerant than it used to be.

    # commands.go('/tidy_fixable_html')

    # forms = [ i for i in b._browser.forms() ]
    # logging.info("forms: %s", forms)
    # assert len(forms) == 0, "there should be no correct forms on this page"

    ###

    commands.go('/BS_fixable_html')
    forms = [ i for i in b._browser.forms() ]
    assert len(forms) == 1, "there should be one mangled form on this page"
开发者ID:JonathanRRogers,项目名称:twill,代码行数:26,代码来源:test-broken-html.py


示例11: authAndRedirect

def authAndRedirect(username, password):
    tw.reset_browser()
    tw.go(SYS_REDIRECT_URL)
    tw.fv('1', "username", username)
    tw.fv('1', "password", password)
    tw.formaction('1', AUTH_URL)
    tw.submit()
    return tw.get_browser().get_html()
开发者ID:liquiddandruff,项目名称:sfu-coursys-viewer,代码行数:8,代码来源:main.py


示例12: url_qs

def url_qs(what):
    browser = get_browser()
    qs = urllib.splitquery(browser.get_url())[-1]
    qs = qs.split('&')
    qsdict = {}
    for q in qs:
        q = q.split('=')
        qsdict[q[0]] = q[1]
        
    if what not in qsdict:
        raise TwillAssertionError("no match to '%s' in %s" % (what, qs))
开发者ID:SMFOSS,项目名称:flunc,代码行数:11,代码来源:urlinspector.py


示例13: split

def split(what):
     """
     >> split <regexp>

     Sets __matchlist__ to re.split(regexp, page).
     """
     page = get_browser().get_html()

     m = re.split(what, page)

     global_dict, local_dict = get_twill_glocals()
     local_dict['__matchlist__'] = m
开发者ID:zenoss,项目名称:twill,代码行数:12,代码来源:__init__.py


示例14: try_posting_disease_model

def try_posting_disease_model(dm, ntries):
    # error handling: in case post fails try again, but stop after 3 tries
    from twill.errors import TwillAssertionError
    import random
    import time

    url = ""
    for ii in range(ntries):
        try:
            url = post_disease_model(dm)
            break
        except TwillAssertionError:
            pass
        if ii < ntries - 1:
            debug("posting disease model failed, retrying in a bit")
            time.sleep(random.random() * 30)
        else:
            debug("posting disease model failed %d times, giving up" % (ii + 1))

    twc.get_browser()._browser._response.close()  # end the connection, so that apache doesn't get upset
    return ""
开发者ID:flaxter,项目名称:gbd,代码行数:21,代码来源:disease_json.py


示例15: provide_formname

 def provide_formname(self, prefix):
     names = []
     forms = commands.get_browser()._browser.forms()
     for f in forms:
         id = f.attrs.get('id')
         if id and id.startswith(prefix):
             names.append(id)
             continue
         name = f.name
         if name and name.startswith(prefix):
             names.append(name)
     return names
开发者ID:zenoss,项目名称:twill,代码行数:12,代码来源:shell.py


示例16: test_global_form

def test_global_form():
    """
    test the handling of global form elements
    """
    b = commands.get_browser()
    commands.config('use_tidy', '0')

    commands.go(url)
    commands.go('/effed_up_forms')
    forms = list(b._browser.forms())
    assert len(forms) == 1
    assert b._browser.global_form()
开发者ID:t0ster,项目名称:twill,代码行数:12,代码来源:test-broken-html.py


示例17: create_user

 def create_user(self, user, pw):
     self.get("/user/create")
     tc.fv("1", "email", user)
     tc.fv("1", "password", pw)
     tc.fv("1", "confirm", pw)
     tc.submit("Submit")
     tc.code(200)
     if len(tc.get_browser().get_all_forms()) > 0:
         p = userParser()
         p.feed(tc.browser.get_html())
         if p.already_exists:
             raise Exception('The user you were trying to create already exists')
开发者ID:ARTbio,项目名称:galaxy,代码行数:12,代码来源:check_galaxy.py


示例18: search_formname

def search_formname (fieldnames, tc):
    """Search form that has all given CGI fieldnames."""
    browser = tc.get_browser()
    for formcounter, form in enumerate(browser.get_all_forms()):
        for name in fieldnames:
            try:
                browser.get_form_field(form, name)
            except tc.TwillException:
                break
        else:
            return form.name or form.attrs.get('id') or formcounter
    # none found
    return None
开发者ID:bootstraponline,项目名称:linkchecker,代码行数:13,代码来源:__init__.py


示例19: findall

def findall(what):
     """
     >> findall <regexp>

     Sets __matchlist__ to re.findall(regexp, page).
     """
     page = get_browser().get_html()

     regexp = re.compile(what, re.DOTALL)
     m = regexp.findall(page)

     global_dict, local_dict = get_twill_glocals()
     local_dict['__matchlist__'] = m
开发者ID:zenoss,项目名称:twill,代码行数:13,代码来源:__init__.py


示例20: css_len

def css_len(css, num):
    num = int(num)

    _, twill_locals = get_twill_glocals()
    browser = get_browser()
    html = browser.get_html()
    tree = lxml.html.document_fromstring(html)
    sel = CSSSelector(css)
    results = sel(tree)

    actual_num = len(results)
    if actual_num != num:
        raise TwillAssertionError('Expected %s matches to "%s"; found %s' % (num, css, actual_num))
开发者ID:socialplanning,项目名称:flunc,代码行数:13,代码来源:xpath.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python commands.go函数代码示例发布时间:2022-05-27
下一篇:
Python commands.fv函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap