[英]Is it possible to take a screenshot of a website using python without having to actually open the website on my pc?
I know that the selenium module can do this, however it has to actually open the site on my computer.我知道 selenium 模块可以做到这一点,但是它必须在我的计算机上实际打开该站点。 The code that I have been using so far is:
到目前为止我一直在使用的代码是:
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.')
I was wondering if there was any other way to do it, without actually having to open the webpage.我想知道是否还有其他方法可以做到这一点,而无需实际打开网页。 Thank you!
谢谢!
You can use imgkit module to take screenshots without opening the site on your computer!无需在电脑上打开网站,即可使用imgkit模块进行截图!
import imgkit
imgkit.from_url('http://google.com', 'out.jpg')
where you can also pass multiple URLs to take screenshots!在这里你还可以传递多个 URL 来截图!
imgkit.from_url(['google.com', 'yandex.ru', 'engadget.com'], 'out.jpg')
There are more ways to make the website's screenshot.有更多方法可以制作网站的屏幕截图。 But, I prefer this, because we can take screenshots with just a line of code!
但是,我更喜欢这个,因为我们只需一行代码就可以截取屏幕截图!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.