当我使用phantomjs,python,selenium创建pdf时,pdf无法完全显示

时间:2018-08-23 15:38:18

标签: python selenium phantomjs

我尝试使用Python + Selenium + PhantomJS技术从链接创建pdf,但将其转换为pdf后我没有完整的图像,请帮忙。我的代码如下:

from selenium import webdriver
import selenium.webdriver.support.ui as ui
from selenium.webdriver.support.ui import WebDriverWait
import time
def download(driver, target_path):
    """Download the currently displayed page to target_path."""
    def execute(script, args):
        driver.execute('executePhantomScript',
                       {'script': script, 'args': args})
    driver.command_executor._commands['executePhantomScript'] = ('POST', '/session/$sessionId/phantom/execute')
    page_zoom = 'this.zoomFactor = {"50%"};'
    execute(page_zoom, [])
    page_viewportSize = 'this.viewportSize = {width: "210mm", height: "297mm"};'
    execute(page_viewportSize, [])
    page_format = 'this.paperSize = {format: "A4", orientation: "portrait"};'
    execute(page_format, [])
    render = '''this.render("{}")'''.format(target_path)
    execute(render, [])
if __name__ == '__main__':
    driver = webdriver.PhantomJS('phantomjs')
    driver.get('https://www.google.com/')
    download(driver, "113.pdf")

incorrect pdf getting after running above code

0 个答案:

没有答案