本文整理汇总了Python中ghost.Ghost.create_page方法的典型用法代码示例。如果您正苦于以下问题:Python Ghost.create_page方法的具体用法?Python Ghost.create_page怎么用?Python Ghost.create_page使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ghost.Ghost
的用法示例。
在下文中一共展示了Ghost.create_page方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test1
# 需要导入模块: from ghost import Ghost [as 别名]
# 或者: from ghost.Ghost import create_page [as 别名]
def test1():
url = "http://www.ebay.com/"
gh = Ghost()
# We create a new page
page, page_name = gh.create_page()
# We load the main page of ebay
page_resource = page.open(url, wait_onload_event=True)
# Full the main bar and click on the search button
page.set_field_value("#gh-ac", "plane")
page.click("#gh-btn")
# Wait for the next page
page.wait_for_selector("#e1-15")
# Save the image of the screen
page.capture_to("plane.png")
示例2: Ghost
# 需要导入模块: from ghost import Ghost [as 别名]
# 或者: from ghost.Ghost import create_page [as 别名]
from ghost import Ghost
url = "http://news.ycombinator.com/"
# We enable the cache and set the maximun size to 10 MB
# We don't want to load images and load css or js files
gh = Ghost(cache_size=10)
# We create a new page
page, page_name = gh.create_page(download_images=False,
prevent_download=["css", "js"])
# wait_onload_event will tell to Ghost to leave the open method
# when the On Ready event on the web page has been fired
page_resource = page.open(url, wait_onload_event=False)
# We retrive the links from the web page
links = page.evaluate("""
var links = document.querySelectorAll("a");
var listRet = [];
for (var i=0; i<links.length; i++){
listRet.push(links[i].href);
}
listRet;
""")
# Print the links
for l in links:
print l
示例3: Ghost
# 需要导入模块: from ghost import Ghost [as 别名]
# 或者: from ghost.Ghost import create_page [as 别名]
from ghost import Ghost
# Creates a Ghost instance telling to don't download css files and images
gh = Ghost()
gpage, name = gh.create_page(download_images=True, prevent_download=["css"])
# Open google
gpage.open("http://www.google.com")
# Saves an image of the screen
gpage.capture_to("/tmp/selective_download.png")
示例4: Ghost
# 需要导入模块: from ghost import Ghost [as 别名]
# 或者: from ghost.Ghost import create_page [as 别名]
from ghost import Ghost
import time
# Creates a Ghost instance telling to share cache and don't share cookies
gh = Ghost(share_cache=True, share_cookies=False)
page1, name = gh.create_page()
page2, name = gh.create_page()
# Open google
page1.open("http://www.google.com", wait_for_loading=False)
# Open Hacker News
page2.open("http://news.ycombinator.com/", wait_for_loading=False)
# At this point ghost it's rendering the two pages at the same time. Now we
# need to check if the pages are loaded.
while page1.get_loaded_page() is None:
page_resource = page1.get_loaded_page()
gh.process_events()
time.sleep(0.01)
# Saves an image of the screen 1
page1.capture_to("/tmp/tab1.png")
print "open /tmp/tab1.png"
#Or we can use wait_for_page_loaded() instead
page2.wait_for_page_loaded()
# Saves an image of the screen 2
page2.capture_to("/tmp/tab2.png")