Posted By

Maximus1983 on 05/29/12


Tagged

library python screen screenshots grab grabzit


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Priestd09


Capture Screenshots in Python


 / Published in: Python
 

URL: http://grabz.it/api/python/

Capture Web Screenshots easily with the GrabzIt Python API

You will need the free GrabzIt Code Library to get started.

  1. #
  2. # The Python that takes the screenshot
  3. #
  4.  
  5. import GrabzItClient
  6.  
  7. #Create the GrabzItClient class
  8. #Replace "APPLICATION KEY", "APPLICATION SECRET" with the values from your account!
  9. grabzIt = GrabzItClient.GrabzItClient("APPLICATION KEY", "APPLICATION SECRET")
  10. #Take the picture the method will return the unique identifier assigned to this task
  11. id = grabzIt.TakePicture("http://www.google.com", "http://www.example.com/GrabzItHandler.py")
  12.  
  13. #
  14. # The GrabzItHandler file that saves the screenshot
  15. #
  16.  
  17. import os
  18. import cgi
  19. import GrabzItClient
  20.  
  21. form = cgi.FieldStorage()
  22.  
  23. message = form.getvalue("message")
  24. customId = form.getvalue("customid")
  25. id = form.getvalue("id")
  26. filename = form.getvalue("filename")
  27.  
  28. #Custom id can be used to store user ids or whatever is needed for the later processing of the
  29. #resulting screenshot
  30.  
  31. grabzIt = GrabzItClient.GrabzItClient("APPLICATION KEY", "APPLICATION SECRET")
  32. result = grabzIt.GetPicture(id)
  33.  
  34. if result != None:
  35. #Ensure that the application has the correct rights for this directory.
  36. fo = open("images" + os.sep + filename, "wb")
  37. fo.write(result)
  38. fo.close()
  39.  
  40. print "Status: 200 OK"
  41. print

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: telikaufman on August 2, 2012

i dont get i it das ot work for me!

You need to login to post a comment.