2 Replies - 497 Views - Last Post: 07 February 2012 - 07:40 AM Rate Topic: -----

Topic Sponsor:

#1 cupidvogel  Icon User is offline

  • D.I.C Addict

Reputation: 29
  • View blog
  • Posts: 522
  • Joined: 25-November 10

Taking screenshot via Python

Posted 07 February 2012 - 02:37 AM

Hi, I know it is possible to read the HTML content of a web-page via Python, but is it possible to capture a screenshot of that page (as it would have been rendered in the browser were it opened) too? For example, if I open the Google homepage in Firefox, press the Print Scrn button to capture the webpage (plus the windows taskbar also), I will have an image in computer memory, which I can paste in Paint to have the screenshot image in bmp format. Is it possible to capture the web-page screenshot after opening the page via

page = urllib2.urlopen("http://www.google.co.in/")



so that I can have the screenshot in computer memory just as if I have opened Google in my browser and taken a screenshot manually?

Is This A Good Question/Topic? 0
  • +

Replies To: Taking screenshot via Python

#2 Motoma  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 443
  • View blog
  • Posts: 792
  • Joined: 08-June 10

Re: Taking screenshot via Python

Posted 07 February 2012 - 06:55 AM

No*. There is however a software package called wkhtmltopdf which contains the wkhtmltoimage, which uses webkit to render a page to an image.
Was This Post Helpful? 1
  • +
  • -

#3 cupidvogel  Icon User is offline

  • D.I.C Addict

Reputation: 29
  • View blog
  • Posts: 522
  • Joined: 25-November 10

Re: Taking screenshot via Python

Posted 07 February 2012 - 07:40 AM

No no, I found what I was looking for, except it involves a third party software called nircommand which does the trick. If I run something like nircmd.exe cmdwait 2000 savescreenshot "C:\temp\shot.png" from the command prompt (after setting the PATH variable to include the path to the nircommand.exe file), the screenshot is taken after 2 seconds (during which I can do anything, for example, minimize all windows including the command prompt so that the screenshot is of my desktop only), and the resulting image is stored in C:\temp as shot.png. So I can use Python to do the trick:

subprocess.call("""nircmd.exe cmdwait 2000 savescreenshot "C:\temp\shot.png" """)



Sorry sorry, I messed up, I forgot what I had asked and wrote the solution to another problem which was bugging me!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1