Javascript 如何使用python获取给定url的屏幕截图

Javascript 如何使用python获取给定url的屏幕截图,javascript,python,python-3.x,selenium,selenium-webdriver,Javascript,Python,Python 3.x,Selenium,Selenium Webdriver,我正在尝试从给定的URL截图。尝试了javascript中的html2canvas库,但由于它不支持某些CSS格式而放弃。现在尝试使用python和selenium或任何其他库(如果可能)捕获给定URL的屏幕截图 我经历了之前的解决方案,我面临的是 1.pyqt4-即使在安装pyqt4之后,也不会出现名为“pyqt4.QtWebKit”的模块错误 2.selenium-代码未截取整个页面滚动的屏幕截图 3.phantom.js-为某些网站提供浮点转储错误 selenium的示例代码: from

我正在尝试从给定的URL截图。尝试了javascript中的html2canvas库,但由于它不支持某些CSS格式而放弃。现在尝试使用python和selenium或任何其他库(如果可能)捕获给定URL的屏幕截图

我经历了之前的解决方案,我面临的是

1.pyqt4-即使在安装pyqt4之后,也不会出现名为“pyqt4.QtWebKit”的模块错误

2.selenium-代码未截取整个页面滚动的屏幕截图

3.phantom.js-为某些网站提供浮点转储错误

selenium的示例代码:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument("--headless") # Runs Chrome in headless mode.
options.add_argument('--no-sandbox') # # Bypass OS security model
options.add_argument('start-maximized')
options.add_argument('disable-infobars')
options.add_argument("--disable-extensions")
driver = webdriver.Chrome(chrome_options=options, executable_path='./chromedriver')
driver.get('https://stackoverflow.com/questions/51000899/better-way-to-take-screenshot-of-a-url-in-python')
driver.save_screenshot('screenshot-headless.png')
driver.quit()

环境:

操作系统:ubuntu 18.04

python:3.6

预期输出:(任意一个)

1.捕获的图像的数据URL

2.拍摄的图像(通过卷轴)

我的代码有什么问题?有其他选择吗?

你试过使用Pypetteer吗

使用
fullPage
参数,您可以拍摄整个页面的屏幕截图

import asyncio
from pyppeteer import launch

async def main():
    browser = await launch(headless=True)
    page = await browser.newPage()

    await page.goto('https://stackoverflow.com/questions/51000899/better-way-to-take-screenshot-of-a-url-in-python')
    await page.screenshot({'path': 'screen.png', 'fullPage': True})
    await browser.close()


asyncio.get_event_loop().run_until_complete(main())
编辑

没有维护。 新项目: