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


Python Ghost.wait_for_alert方法代码示例

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


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

示例1: unloadScrollBars

# 需要导入模块: from ghost import Ghost [as 别名]
# 或者: from ghost.Ghost import wait_for_alert [as 别名]
                function unloadScrollBars() {
                    document.documentElement.style.overflow = 'hidden';
                    document.documentElement.scroll = "no";
                    document.body.style.overflow = 'hidden';
                    document.body.scroll = "no";
                }
                unloadScrollBars();
                alert("done");
"""

javascriptCode = injectJqueryIfNeededAndThenRun(jquerycode)


result, resources = ghost.evaluate(javascriptCode)

result, resources = ghost.wait_for_alert()


print "Runned code :"
print javascriptCode



#jQuery(function($) {
#    'use strict';
#    $('#apDiv2').show().parentsUntil('body').andSelf().siblings().hide();
#    /* one item */
#/ *li:first-child:nth-last-child(1) { */
#    $('#apDiv2').show().parentsUntil('body',':only-child').andSelf().css('margin-top', '200px').css('margin-bottom','200px');
#    $('#apDiv2').show().parentsUntil('body',':not(:only-child)').css('height', '600px');
#;
开发者ID:onilton,项目名称:pageavatar-xtractor,代码行数:33,代码来源:extractHeader.py

示例2: Crawler

# 需要导入模块: from ghost import Ghost [as 别名]
# 或者: from ghost.Ghost import wait_for_alert [as 别名]

#.........这里部分代码省略.........
                print e['onclick'], 'no page loaded'
            except:
                print traceback.format_exc()
        self.ghost.wait_timeout = page_timeout

        #获取超链接
        array = soup.find_all('a')
        for a in array:
            try:
                continue_flag = 0
                url = standard(target_url, a['href'])
                for k in ['javascript:;', 'return false;', 'logout']:
                    if url.lower().find(k) != -1:
                        continue_flag = 1
                        break
                if continue_flag == 1:
                    continue
                if url.startswith('http'):
                    self.__add_url(all_url, url) #url
                elif url not in url_queue and not url.startswith('#'):
                    url_queue.append(url)
                    self.ghost.click(\'''a[href="%s"]\''' % url, expect_loading=True)
                    url, resources = self.ghost.evaluate('window.location.href')
                    if url != target_url:
                        self.__add_url(all_url, str(url))
                        self.ghost.open(target_url)
            except TimeoutError:
                print url, 'failed'
            except KeyError:
                pass
            except:
                print url, traceback.format_exc()
        '''
        #获取表单
        target_forms = []
        forms = soup.find_all('form')
        for input, form in enumerate(forms):
            names = []
            inputs = form.find_all('input', type=lambda type: type == 'text' or type == 'password'or not type)
            texts = form.find_all('textarea')
            for input in inputs:
                try:
                    names.append(input['name'])
                except KeyError:
                    pass
            for text in texts:
                try:
                    names.append(text['name'])
                except KeyError:
                    pass
            if len(names) > 0:
                target_forms.append((input, sorted(names)))
        print 'target', target_forms
        for input, names in target_forms:
            self.submit_xss(all_url, target_url, input, names) #表单序号及其所有输入框
            #深度优先
        for url in all_url:
            self.__page_crawler(url, depth + 1)

    def __del__(self):
        self.ghost.exit()

    def submit_xss(self, all_url, target_url, form_i, names):
        for input, xss in enumerate(xss_rsnake):
            print 'submit', names, xss
            try:
                if input > 0:
                    self.ghost.open(target_url)
                for name in names:
                    try:
                        self.ghost.evaluate(
                            "document.querySelectorAll('*[name=%s]')[0].removeAttribute('onfocus');" % name)
                        #填写表单
                        self.ghost.set_field_value("*[name=%s]" % name, xss)
                    except:
                        print traceback.format_exc()
                self.ghost.evaluate(
                    "document.querySelectorAll('input[type=submit]')[0].removeAttribute('onclick');")

                #提交表单 自动
                self.ghost.click('input[type=submit]')#, expect_loading=True)
                #self.ghost.evaluate(
                 #   "document.querySelectorAll('form')[%d]['submit']();" % form_i)#, expect_loading=True)

                try:
                    self.ghost.wait_timeout = alert_timeout
                    result, resources = self.ghost.wait_for_alert()
                    print '============================================================'
                    print 'alert:', result
                    print '============================================================'
                    if result == 'XSS':
                        break
                except TimeoutError:
                    pass
                finally:
                    self.ghost.wait_timeout = page_timeout
                    url, resources = self.ghost.evaluate('window.location.href')
                    self.__add_url(all_url, str(url))
            except TimeoutError:
                print 'failed'
开发者ID:surpassly,项目名称:front,代码行数:104,代码来源:backup.py

示例3: Bridge

# 需要导入模块: from ghost import Ghost [as 别名]
# 或者: from ghost.Ghost import wait_for_alert [as 别名]
class Bridge(object):

  def __init__(self, **kwargs):
    kwargs.setdefault('wait_timeout', 60)
    self.user_id = kwargs.pop('user_id')
    self.access_token = kwargs.pop('access_token')
    self.server_host = kwargs.pop('server_host')
    self.server_port = kwargs.pop('server_port')
    self.ghost = Ghost(**kwargs)
    self.callbacks = {}

  def open(self):
    self.ghost.open('http://%(host)s:%(port)s' % dict(
      host=self.server_host,
      port=self.server_port,
    ))

  def js(self, script, *args):
    args = ', '.join(map(json.dumps, args))
    script += '(' + args + ')'
    import q; q(script)
    return self.ghost.evaluate(script)

  def open_file(self, file_id):
    self.js('Overdrive.open', file_id, self.user_id,
            self.access_token)

  def create_file(self, title, content, index):
    self.js('Overdrive.create', title, content, index, self.user_id,
            self.access_token)

  def set_view(self, view):
    self.js('Overdrive.setView', view)

  def set_text(self, text):
    self.js('Overdrive.setText', text)

  def set_ref(self, index):
    self.js('Overdrive.setRef', index)

  def close_session(self):
    self.js('Overdrive.setRef', -1)

  def call_event(self, event):
    for callback in self.callbacks.get(str(event.pop('type')), []):
      callback(**event)

  def wait(self):
    self.waiting = True
    while self.waiting:
      try:
        self.ghost.wait_for_alert()
      except Exception as e:
        if str(e) != 'User has not been alerted.':
          raise
      else:
        self.stop()

  def on(self, type):
    def wrapper(f):
      self.callbacks.setdefault(type, []).append(f)
      return f
    return wrapper

  def stop(self):
    self.waiting = False
开发者ID:akosipc,项目名称:overdrive,代码行数:68,代码来源:odbridge.py


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