Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Take a screenshot from a website from commandline or with python

i will take a screenshot from this page: http://books.google.de/books?id=gikDAAAAMBAJ&pg=PA1&img=1&w=2500 or save the image that it outputs.

But i can't find a way. With wget/curl i get an "unavailable error" and also with others tools like webkit2png/wkhtmltoimage/wkhtmltopng.

Is there a clean way to do it with python or from commandline?

Best regards!

like image 712
danbruegge Avatar asked May 02 '13 18:05

danbruegge


People also ask

How do I take a screenshot of a webpage using Python?

In order to take a screenshot of webpage save_screenshot() method is used. save_screenshot method allows user to save the webpage as a png file. Argument : filename or the full path you wish to save your screenshot to.

Can you take a screenshot with Python?

Method 1: Using pyautogui module The pyautogui module makes use of the screenshot function which is responsible for taking the screenshot of the whole computer screen. And then the save function is used to save the screenshot captured to our device.

How do I take a screenshot in Terminal?

Alt + PrtSc – Save a screenshot of the current window to Pictures. Ctrl + PrtSc – Copy the screenshot of the entire screen to the clipboard.


2 Answers

You can use ghost.py if you like. https://github.com/jeanphix/Ghost.py

Here is an example of how to use it.

from ghost import Ghost
ghost = Ghost(wait_timeout=4)
ghost.open('http://www.google.com')
ghost.capture_to('screen_shot.png')

The last line saves the image in your current directory.

Hope this helps

like image 196
Sason Torosean Avatar answered Sep 20 '22 17:09

Sason Torosean


I had difficulty getting Ghost to take a screenshot consistently on a headless Centos VM. Selenium and PhantomJS worked for me:

from selenium import webdriver
br = webdriver.PhantomJS()
br.get('http://www.stackoverflow.com')
br.save_screenshot('screenshot.png')
br.quit
like image 43
billrichards Avatar answered Sep 20 '22 17:09

billrichards