简体   繁体   English

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

[英]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.

相关问题 用python脚本拍摄打开的网站的屏幕截图 - Take a screenshot of open website in python script 技术上是否可以通过编程方式截取网站的屏幕截图? - Is it technically possible to take a screenshot of a website programmatically? 如何使用 Python 截取网站的屏幕截图/图片? - How can I take a screenshot/image of a website using Python? 从命令行或使用 python 从网站截取屏幕截图 - Take a screenshot from a website from commandline or with python Python 是否可以在不打开浏览器的情况下从网站播放声音/音乐? - Is it possible in Python to play sound/music from website without open the browser? 打开excel并使用python selenium截取屏幕截图 - open excel and take screenshot using python selenium 如何使用 python 从网站截取屏幕截图? - How do i take screenshot from website with python? 使用 Python 的网站屏幕截图 (Windows) - Screenshot of a website with Python (Windows) 是否可以使用python脚本在浏览器(Chrome / Firefox)中打开网站? - Is it possible to open a website in a browser (Chrome/Firefox) using python script? 是否可以打开一个网站,然后使用 Python 在其中运行 JavaScript? - Would it be possible to open a website and then run JavaScript in it using Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM