是否可以使用 python 截取网站的屏幕截图而无需在我的电脑上实际打开该网站?

Is it possible to take a screenshot of a website using python without having to actually open the website on my pc?

我知道 selenium 模块可以做到这一点,但它必须在我的计算机上实际打开网站。到目前为止我一直使用的代码是:

site_name='any site here'
    try:
        driver.get(site_name)
        await asyncio.sleep(1)
        driver.save_screenshot(r'C:\Users\username\Desktop\Bonfire\Webpage Screenshots\screengrab.png')
        await ctx.send(file=discord.File(r'C:\Users\username\Desktop\Bonfire\Webpage Screenshots\screengrab.png'))
    except:
        await ctx.send('Your URL is wrong or that site does not exist anymore.')

我想知道是否有任何其他方法可以做到这一点,而无需实际打开网页。谢谢!

您可以使用imgkit模块进行屏幕截图,而无需在您的计算机上打开网站!

import imgkit
imgkit.from_url('http://google.com', 'out.jpg')

这里也可以传递多个网址进行截图!

imgkit.from_url(['google.com', 'yandex.ru', 'engadget.com'], 'out.jpg')

网站截图的制作方法更多了。但是,我更喜欢这个,因为我们只需要一行代码就可以截屏!