यहाँ एक समाधान GhostDriver के लिए सेलेनियम और विशेष आदेश का उपयोग है (यह GhostDriver 1.1.0 और बाद PhantomJS 1.9 काम करना चाहिए। 6, PhantomJS 1.9.8) के साथ परीक्षण किया:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Download a webpage as a PDF."""
from selenium import webdriver
def download(driver, target_path):
"""Download the currently displayed page to target_path."""
def execute(script, args):
driver.execute('executePhantomScript',
{'script': script, 'args': args})
# hack while the python interface lags
driver.command_executor._commands['executePhantomScript'] = ('POST', '/session/$sessionId/phantom/execute')
# set page format
# inside the execution script, webpage is "this"
page_format = 'this.paperSize = {format: "A4", orientation: "portrait" };'
execute(page_format, [])
# render current page
render = '''this.render("{}")'''.format(target_path)
execute(render, [])
if __name__ == '__main__':
driver = webdriver.PhantomJS('phantomjs')
driver.get('http://stackoverflow.com')
download(driver, "save_me.pdf")
भी एक ही सवाल here को मेरा उत्तर देखें।
क्या आपने Pypdf2 को देखा है? http://www.blog.pythonlibrary.org/tag/python-pdf-series/ – Amit
@ प्रवेश: बल्कि बड़े पैमाने पर, क्योंकि मैं इसे हर समय उपयोग करता हूं। यहां तक कि फसीट ने खुद कहा है कि "पीईपीडीएफ 2 को एचटीएमएल का कोई ज्ञान नहीं है"। यह किसी भी एचटीएमएल विश्वसनीय रूप से प्रस्तुत नहीं करेगा। – Rejected
@ अस्वीकृत क्या आपको परीक्षण के दौरान सटीक स्थिति में होने वाले स्क्रीनशॉट की आवश्यकता है? या आप सिर्फ एक पेज लोड करना चाहते हैं और पीडीएफ में प्रस्तुत करना चाहते हैं? –