繁体   English   中英

是否可以使用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')

在这里你还可以传递多个 URL 来截图!

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM