Capture Screenshots in Python


/ Published in: Python
Save to your folder(s)

Capture Web Screenshots easily with the [GrabzIt ](http://grabz.it/) Python API

You will need the free [GrabzIt Code Library](http://grabz.it/api/python/download.aspx) to get started.


Copy this code and paste it in your HTML
  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

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.