简体   繁体   中英

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. 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!

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

where you can also pass multiple URLs to take screenshots!

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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