Take a screenshot of open website in python script

孤街浪徒 提交于 2019-11-29 15:42:13

This solution is fairly cross-platform, but if you're trying to show a bit of a web page open in a desktop with menu/toolbars etc... it's not what you want.

You could use SeleniumHQ to automate a browser of your choice, have that browser render the page, then get the complete image of the rendered page - ie, not just a screenshot of the portion of the page that's displayed on screen. You could then crop that accordingly.

Jan-Philip Gehrcke

I believe that you need different solutions for different operating systems. Use sys.platform to find out on which platform you are on. The rest you have to figure out yourself, but a quick internet search revealed:

  • On Linux systems, you can then take a screenshot as described here:

Take a screenshot via a python script. [Linux]

  • On Windows systems, you can base your solution on this answer:

Fastest way to take a screenshot with python on windows

  • On Mac systems, this will help:

Take screenshot in Python on Mac OS X

inspectorG4dget

According to this question, you should be able to use ImageGrab to take a screenshot. Since ImageGrab uses PIL, this should be cross-platform. Here is some sample code to get you on your way

Hope this helps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!