簡體   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