import sys sys.path.append("..") import pykhtml pykhtml.debugWithGUI = True def takeScreenshot(browser): # Take the screenshot. Simple. File type can be specified # manually or determined from extension browser.screenshot("screenshot.png", screenshotFinished) def screenshotFinished(): print "screenshot saved to `screenshot.png`" # Stop here, we're done pykhtml.stopEventLoop() def main(): browser = pykhtml.Browser() # if a URL has been specified, use that instead if len(sys.argv) > 1: url = sys.argv[1] else: url = "http://paul.giannaros.org/pykhtml" # load the page. takeScreenshot will be called when it has # been loaded browser.load(url, takeScreenshot) pykhtml.startEventLoop() if __name__ == "__main__": main()