from selenium import webdriver
import selenium
def execute(script, args):
driver.execute('executePhantomScript', {'script': script, 'args' : args })
driver = webdriver.PhantomJS('phantomjs')
# hack while the python interface lags
driver.command_executor._commands['executePhantomScript'] = ('POST', '/session/$sessionId/phantom/execute')
driver.get('https://www.sina.com')
# set page format
# inside the execution script, webpage is "this"
pageFormat = '''this.paperSize = {format: "Legal", orientation: "portrait" };'''
execute(pageFormat, [])
# render current page
render = '''this.render("demo.pdf")'''
execute(render, [])
phantom.js 下载地址 http://phantomjs.org/download.html