本文整理汇总了Python中ghost.Ghost.wait_timeout方法的典型用法代码示例。如果您正苦于以下问题:Python Ghost.wait_timeout方法的具体用法?Python Ghost.wait_timeout怎么用?Python Ghost.wait_timeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ghost.Ghost
的用法示例。
在下文中一共展示了Ghost.wait_timeout方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: snap
# 需要导入模块: from ghost import Ghost [as 别名]
# 或者: from ghost.Ghost import wait_timeout [as 别名]
def snap(conn, url, cookie_name, cookie_value, width, height, loaded, hides, selector):
"""Handle all the work of taking the page snapshot.
The first parameter is a connection object for a `multiprocessing.Pipe`
that we use to send back the file name written to. The remaining parameters
are `multiprocessing.Value`s.
"""
ghost = None
try:
ghost = Ghost(viewport_size=(width.value, height.value))
ghost.wait_timeout = 20
headers = {}
if cookie_name.value and cookie_value.value:
headers = {
'Cookie': str('%s=%s' % (cookie_name.value, cookie_value.value)),
}
ghost.open(url.value, headers=headers)
if loaded.value:
try:
ghost.wait_for_selector('%s' % loaded.value)
except:
# if the selector never appears, we don't care
pass
selectors = hides.value.split(',')
if len(selectors):
hide_js = r'''
if (jQuery) {
$(document).ready(function() {
%s
});
}
''' % '\n'.join([r"$('%s').hide();" % sel for sel in selectors])
ghost.evaluate(hide_js)
handle, file_path = mkstemp(prefix='ansel_snap', suffix='.png')
ghost.capture_to(file_path, selector=selector.value)
conn.send(file_path)
finally:
del ghost
conn.close()
示例2: heroku
# 需要导入模块: from ghost import Ghost [as 别名]
# 或者: from ghost.Ghost import wait_timeout [as 别名]
def heroku(api_key, year, month):
ghost = None
file_path = '/tmp/heroku_invoice_%d-%d.png' % (year, month)
if os.path.exists(file_path):
os.remove(file_path)
# TODO: make dimensions configurable? Automatic (is that possible?)?
ghost = Ghost(viewport_size=(1000, 1600))
ghost.wait_timeout = 20
ghost.open('https://id.heroku.com/login')
ghost.fill("form", dict(email="", password=api_key))
ghost.fire_on("form", "submit", expect_loading=True)
ghost.open('https://dashboard.heroku.com/invoices/%s/%s' % (year, month))
ghost.capture_to(file_path)
return file_path