博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
selenium+phantomjs+python 将html导出pdf
阅读量:6511 次
发布时间:2019-06-24

本文共 719 字,大约阅读时间需要 2 分钟。

  hot3.png

from selenium import webdriverimport seleniumdef execute(script, args):    driver.execute('executePhantomScript', {'script': script, 'args' : args })    driver = webdriver.PhantomJS('phantomjs')# hack while the python interface lagsdriver.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 pagerender = '''this.render("demo.pdf")'''execute(render, [])

 

phantom.js 下载地址  http://phantomjs.org/download.html

转载于:https://my.oschina.net/u/1778309/blog/900608

你可能感兴趣的文章