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


Python ghost.Ghost类代码示例

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


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

示例1: test_1

def test_1():
    from ghost import Ghost
    ghost = Ghost()
    page, extra_res = ghost.open('http://www.baidu.com')

    print(page.http_status)
    print(ghost.content)
开发者ID:saiwei13,项目名称:QQ_msg_backup,代码行数:7,代码来源:py_exec_js.py

示例2: ghost_img

def ghost_img(src):
	ghost = Ghost()
	page,resources = ghost.open(src)
	ghost.wait_for_page_loaded()  
	result, resources = ghost.evaluate("document.getElementById('largeImg').getAttribute('src');" ) 
	del resources
	return result
开发者ID:defkf,项目名称:python_exercis,代码行数:7,代码来源:pa_68_2.py

示例3: index

def index(request):
    dir_name = os.path.dirname(__file__)
    img_name = os.path.join(dir_name, "pic.jpg")

    if request.method == "POST":
        url = request.POST.get("url", "")
    else:
        url = request.GET.get("url", "")

    if not url:
        url = "http://www.bbc.uk.com"

    display = Display()
    display.start()

    ghost = Ghost()
    ghost.open(url)
    width = int(ghost.evaluate("document.body.clientWidth")[0])
    height = int(ghost.evaluate("document.body.clientHeight")[0])

    ghost = Ghost(viewport_size=(width, height))
    ghost.open(url)
    ghost.capture_to(img_name, selector="body")

    image = Image.open(img_name)
    image.thumbnail((128, 128), Image.ANTIALIAS)

    response = HttpResponse(mimetype="image/jpeg")
    image.save(response, "jpeg")

    display.stop()

    return response
开发者ID:preom,项目名称:websiteSnapshot,代码行数:33,代码来源:views.py

示例4: break_protection

 def break_protection(self, target):
     print('\nAttempting ClickJacking... \n')
     html = '''
     <html>
     <body>
     <iframe src="'''+target+'''" height='600px' width='800px'></iframe>
     </body>
     </html>'''
     html_filename = 'clickjack.html'
     f = open(html_filename, 'w+')
     f.write(html)
     f.close()
     abs_path = os.path.abspath(os.path.dirname(__file__))
     log_filename = abs_path+'/../../Logs/'+'Clickjacking.log'
     fh = logging.FileHandler(log_filename)
     ghost = Ghost(log_level=logging.INFO, log_handler=fh)
     with ghost.start() as session:
         session.wait_timeout = 50
         page, resources = session.open(html_filename)
         l = open(log_filename, 'r')
         if 'forbidden by X-Frame-Options.' in l.read():
             print('Clickjacking mitigated via X-FRAME-OPTIONS')
         else:
             href = session.evaluate('document.location.href')[0]
         if html_filename not in href:
             print('Frame busting detected')
         else:
             print(colored('Frame busting not detected, page is likely ' +
                           'vulnerable to ClickJacking', 'red'))
         l.close()
         logging.getLogger('ghost').handlers[0].close()
         os.unlink(log_filename)
         os.unlink(html_filename)
开发者ID:a0xnirudh,项目名称:WebXploiter,代码行数:33,代码来源:clickjacking.py

示例5: grab_url_screenshot

def grab_url_screenshot(url):
    """
    Grab an url making a screenshot of it
    Filename is SHA256 of url
    :param url:
    :return:
    """

    ret = None

    try:
        # Bonifica url (se manca lo schema assumo http://)
        url_res = urlparse(url)
        if not url_res.scheme:
            url = "http://" + url

        # TODO: Può essere un singleton Ghost?
        ghost = Ghost()
        page, res = ghost.open(url)
        if not page is None and page.http_status == 200:
            url_sha256 = hashlib.sha256(url).hexdigest()
            image_path = os.path.join('url_previews', url_sha256 + ".png")
            full_path = os.path.join(settings.MEDIA_ROOT, image_path)

            ghost.capture_to(full_path)

            image_path = image_path.replace(".png", ".thumb.png")
            thumb_full_path = os.path.join(settings.MEDIA_ROOT,image_path)
            resize_and_crop(full_path, thumb_full_path, (550, 500))
            ret = urljoin(settings.BASE_URL,  "uploads/" + image_path)
        else:
            logger.error("Failed to capture screenshot for {0}".format(url))
    except Exception, e:
        logger.exception(e)
开发者ID:poladura,项目名称:pushetta-api-django,代码行数:34,代码来源:utility.py

示例6: getHtml

 def getHtml(self):
   ghost = Ghost()
   with ghost.start() as session:
     page, extra_resources = session.open(self.url,'get',{},None,None,None,True,30)
     if page.http_status == 200:
       return session.content
   return False
开发者ID:shiyangwu520,项目名称:Docker,代码行数:7,代码来源:ghostpy.catcher.py

示例7: test_6

def test_6():
    from ghost import Ghost

    base_url = 'http://127.0.0.1:8888'

    ghost = Ghost()
    ghost.open(base_url)
开发者ID:saiwei13,项目名称:QQ_msg_backup,代码行数:7,代码来源:py_exec_js.py

示例8: gethtml

def gethtml(URL):
	ghost = Ghost(wait_timeout=120)
	try:
		page, resources = ghost.open(URL)
		html = BeautifulSoup(ghost.content)
	except Exception as EX:
		print(EX)
	return html
开发者ID:sandy420,项目名称:GetBrokers,代码行数:8,代码来源:FangTianxia.py

示例9: vision

def vision(ghost):
	
	if ghost.inHeaven == True:
		ghost = Ghost()
		
	print("While sleeping, you have a strange dream....")
	print("A ghostly figure appears in front of you and begins to speak.\n")
	ghost.display_message()
开发者ID:AllisonKuhl,项目名称:hist4006-cluny-final-project,代码行数:8,代码来源:randomEvents.py

示例10: Shazam

class Shazam(object):
    """
    Provides methods for downloading Shazam history
    """

    def __init__(self, fb_email=None, fb_password=None):
        self.session = Ghost().start()
        self.facebook = Facebook(self.session, fb_email, fb_password)
        self.login_successful = False
        self.fat = None # Facebook access token

    def login(self):
        """
        Performs Shazam login
        :return: bool - True if success, False - otherwise
        """

        if self.login_successful:
            return True

        if not self.facebook.login():
            return False

        # fat = self.facebook.get_access_token(app_id)
        # if not fat:
        #     logging.error("Couldn't get Facebook access token")
        #     return False
        #
        # user_id = self.facebook.get_user_id()
        # if not user_id:
        #     logging.error("Couldn't get Facebook user id")
        #     return False
        #
        # query = [("fat", fat),
        #          ("uid", user_id)]
        # body = urllib.urlencode(query)
        # login_url = "http://www.shazam.com/login"
        # try:
        #     self.session.open(login_url,
        #                       method="post",
        #                       body=body)
        # except Exception, e:
        #     logging.error("Shazam login failed")
        #     logging.error(str(e))
        #     return False
        myshazam_url = "http://www.shazam.com/myshazam"
        try:
            self.session.open(myshazam_url)
        except Exception, e:
            logging.error("Shazam login failed. Couldn't open myshazam page.")
            logging.error(str(e))
            return False
        try:
            self.session.click(".js-fblogin")
        except Exception, e:
            logging.error("Shazam login failed. Couldn't click login button.")
            logging.error(str(e))
            return False
开发者ID:kharts,项目名称:music_explorer,代码行数:58,代码来源:shazam.py

示例11: main

def main():
    """
    Go to across pages
    """
    if not b_extraction:
        global ghost
        ghost = Ghost()
        global session
        session = ghost.start(download_images=False, show_scrollbars=False, wait_timeout=5000, display=False,
                              plugins_enabled=False)
        logger.info("Start - ČAK")
        session.open(url)
        list_of_links = None
        if session.exists("#mainContent_btnSearch") and not b_extraction:
            session.click("#mainContent_btnSearch", expect_loading=True)
            if session.exists("#mainContent_gridResult"):
                value, resources = session.evaluate("document.getElementById('mainContent_lblResult').innerHTML")
                logger.debug(value)
                records, pages = how_many(value, 50)
                #pages = 99 # hack for testing
                page_from = 1
                logger.info("Checking records...")
                list_of_links = check_records(page_from, pages)
        if len(list_of_links) > 0:
            logger.info("Dowload new records")
            for record in list_of_links:
                #print(record)#,record["url"],record["id"])
                # may it be wget?
                if not os.path.exists(join(documents_dir_path, record["id"] + ".html")):
                    import urllib.request
                    try:
                        urllib.request.urlretrieve(record["url"], join(documents_dir_path, record["id"] + ".html"))
                    except urllib.request.HTTPError as ex:
                            logger.error(ex.msg, exc_info=True)

                            #session.open(record["url"])
                            #response = str(urlopen(record["url"]).read())
                            #response = session.content
                            #extract_data(response, record["id"]+".html")

            logger.info("Download  - DONE")
            session.exit()
            ghost.exit()
        else:
            logger.info("Not found new records")
            list_of_links = None

        if list_of_links is not None:
            logger.info("Extract information...")
            extract_information(list_of_links)
            logger.info("Extraction  - DONE")
    else:
        if b_extraction:
            logger.info("Only extract information...")
            extract_information(list_of_links=None)
            logger.info("Extraction  - DONE")
    return True
开发者ID:datoszs,项目名称:the-czech-bar-association,代码行数:57,代码来源:cak-crawler.py

示例12: gethtml

def gethtml(URL):
    ghost = Ghost(wait_timeout=120)
    try:
        page, resources = ghost.open(URL)
        html = BeautifulSoup(ghost.content)  # ,from_encoding='GB18030')
    except Exception as EX:
        print(EX)
    print(html)
    return html
开发者ID:sandy420,项目名称:GetBrokers,代码行数:9,代码来源:fccs.py

示例13: getCartoonUrl

def getCartoonUrl(self, url):
  if url is None:
    return false
  #todo many decide about url
  ghost = Ghost()
  #open webkit
  ghost.open(url)
  #exceute javascript and get what you want
  result, resources = ghost.evaluate("document.getElementById('cp_image').getAttribute('src');")
  del resources
  return result
开发者ID:zhibzeng,项目名称:PythonCode,代码行数:11,代码来源:GhostDemo2.py

示例14: Client

class Client(object):
    def __init__(self, url=None):
        if url:
            self.url = url
        assert self.url, "All clients must have a URL attribute"
        self._attributes = self._collect_attributes()
        self._class_model = self._setup_class_model()
        self._ghost = Ghost()

    def process(self):
        self._load_ghost()
        attribute_results = self._process_attributes()
        self._object_results = self._make_objects(attribute_results)
        return self._object_results

    def _setup_class_model(self):
        class_name = self.__class__.__name__
        return namedtuple(class_name + "Response", self._attributes.keys())

    def _process_attributes(self):
        results = []
        for attribute_name, attribute in self._attributes.iteritems():
            result, resources = self._ghost.evaluate(attribute.query)
            # If a node was selected, return it's data
            if isinstance(result, dict):
                if 'data' in result:
                    result = result['data']
                elif 'selector' in result:
                    raise TypeError("The attribute {} returned a selector"
                        " instead of a node.".format(attribute_name))
            results.append(result)
        return results

    def _make_objects(self, attribute_results):
        raise NotImplementedError()

    def _collect_attributes(self):
        attrs = [(attr_name, attr) for (attr_name, attr) in
            inspect.getmembers(self) if isinstance(attr, Attribute)]
        return dict(attrs)

    def _load_ghost(self):
        page, extra_resources = self._ghost.open(self.url)

        # For local testing, page is None
        if page:
            # TODO should error better
            assert page.http_status < 400

        # Load jquery
        jquery_path = os.path.join(os.path.abspath(os.curdir),
                            'zester', 'fixtures', 'jquery.min.js')
        jquery_text = open(jquery_path, 'r').read()
        result, resources = self._ghost.evaluate(jquery_text)
开发者ID:msabramo,项目名称:zester,代码行数:54,代码来源:client.py

示例15: main

def main(argv):
    if len(argv) < 2:
        sys.stderr.write("Usage: %s <url>\n" % (argv[0],))
        return 1

    ghost = Ghost(viewport_size=(1280, 1024))
    page, resources = ghost.open(argv[1])
    assert page.http_status==200 and 'bbc' in ghost.content
    ghost.capture_to('screenshot2.png')

    for r in resources:
      print r.url
开发者ID:leepro,项目名称:strender,代码行数:12,代码来源:flashfreeze.py


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