Tools to Capture and Convert the Web

Take Website Screenshots with Python Screenshot API

Python API
The diagnostics panel can help you debug your code!

GrabzIt's screenshot API is very flexible and can be called from a cronjob, a web page or app. The easiest way to add website screenshots or converting HTML to images, PDF and DOCX. To your Python app is by following these steps:

  1. Get your free key and secret.
  2. Download the free Python Library manually or via pip install and try out the demo app.
  3. Find out the basics about how GrabzIt's API works by reading the below overview.

Python API Overview

To use the API, you will first need to create an instance of the GrabzItClient class. Then pass your key and secret from your GrabzIt account to the constructor.

from GrabzIt import GrabzItClient

# Create the GrabzItClient class
# Replace "APPLICATION KEY", "APPLICATION SECRET" with the values from your account!
grabzIt = GrabzItClient.GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret")

Next you will need to use one of the image, PDF, animation or table methods. To request that the GrabzIt service capture the URL passed to it. Or convert HTML into an image, JPG or DOCX file.

# To take a image screenshot
grabzIt.URLToImage("https://www.tesla.com") 	
# Or to take a PDF screenshot
grabzIt.URLToPDF("https://www.tesla.com")
# Or to convert online videos into animated GIF's
grabzIt.URLToAnimation("http://www.example.com/video.avi")
# Or to capture table(s)
grabzIt.URLToTable("https://www.tesla.com")
# To convert HTML into a image
grabzIt.HTMLToImage("<html><body><h1>Hello World!</h1></body></html>")	
# Or convert HTML into a PDF document
grabzIt.HTMLToPDF("<html><body><h1>Hello World!</h1></body></html>")
# Or convert HTML into a CSV, XLSX or JSON document
grabzIt.HTMLToTable("<html><body><table><tr><th>Name</th><th>Age</th></tr>
    <tr><td>Tom</td><td>23</td></tr><tr><td>Nicola</td><td>26</td></tr>
    </table></body></html>")
# To convert HTML file into a image
grabzIt.FileToImage("example.html") 	
# Or convert HTML file into a PDF document
grabzIt.FileToPDF("example.html")
# Or convert HTML file into a CSV, XLSX or JSON document
grabzIt.FileToTable("tables.html")

Finally, one of the two following save methods must be used to retrieve the capture. The recommended Save method requires the URL of a handler such as handler.py. This enables the capture to be retrieved asynchronously. This stops your app having to wait while a screenshot is created, and because it eliminates the need to repeatedly poll GrabzIt could potentially be faster.

grabzIt.Save("http://www.example.com/handler.py") 	
Always use the SaveTo method on localhost

The other save method is the synchonous SaveTo method, while this is simpler to use. It will force your app to wait while the screenshot is created.

So it should only be used in situations were the Save method cannot be used, such as in a desktop application or on localhost.

filepath = "images/result.jpg"
grabzIt.SaveTo(filepath) 	

More Options

There are many more options when screenshots from web pages or converting HTML. Including; configuring the browser height and width, screenshot height and width. The delay before a capture is taken and the format of the capture. Find all these options and much more in the GrabzIt Client documentation.