selenium+phantomjs+python 將html導出pdf

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.htmlhtml

相關文章
相關標籤/搜索