【问题标题】:Convert a full webpage to a PDF or combine screenshots into one image将整个网页转换为 PDF 或将屏幕截图合并为一张图像
【发布时间】:2020-01-23 11:14:43
【问题描述】:

我正在寻找将网页转换为 PDF 的方法。我像“截取所有网页的屏幕截图”一样搜索了这个。在任何地方,每个人都提到python“selenium”模块。但没有找到任何关于“所有页面”的信息。不想单张截图。我的 whis 就像 PDF 格式。

已经尝试过imgkit。有什么办法吗?

【问题讨论】:

    标签: python-3.x screenshot


    【解决方案1】:

    似乎有一个叫做 pdfkit 的东西,也是 python 的 wkhtmltopdf 包装器。

    https://github.com/JazzCore/python-pdfkit

    另外,我会推荐 CutyCapt,如果它不必是 python 库。

    http://cutycapt.sourceforge.net/

    【讨论】:

    • 确实如此。我正在尝试使用 python 来执行此操作,因为我的程序中需要此功能。对我来说有点挑战。还是谢谢。
    • 我有一些丑陋的错误。但我找到了答案
    【解决方案2】:

    我找到了答案。第一个模块的名称是“Selenium-Screenshot”。它截取屏幕截图并在一张图像中进行比较。更详细的讨论: Taking a whole page screenshot with Selenium Marionette in Python

    from Screenshot import Screenshot_Clipping
    from selenium import webdriver
    
    ob=Screenshot_Clipping.Screenshot()
    
    options = webdriver.ChromeOptions()   #created for headless chrome
    options.add_argument('headless')
    options.add_argument('window-size=1920x1080')    #change resolution of screenshots
    
    driver = webdriver.Chrome(chrome_options=options)
    url = "your_url"
    driver.get(url)
    img_url=ob.full_Screenshot(driver, save_path=r'.', image_name='Myimage.png')
    driver.close()
    driver.quit()
    

    【讨论】:

      猜你喜欢
      • 2013-07-15
      • 1970-01-01
      • 1970-01-01
      • 2013-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-18
      相关资源
      最近更新 更多