The python library can be installed from PyPI.
sudo pip install -U simplejson browshot
The source code is available on GitHub.
Here are a couple of basic code samples. You can find more code samples for each API call on the API Documentation page.
# -*- coding: utf-8 -*-
#######################
# WARNING
# Running this code sample will cost you Browshot credits
#######################
from browshot import BrowshotClient
browshot = BrowshotClient('my_api_key')
data = browshot.simple('http://mobilito.net/', { 'cache': 60 * 60 * 24 * 365, 'instance_id': 12 }) # 1 year cache, free screenshot
# code above is blocking, it will return when the screenshot finished or failed
if int(data['code']) == 200: # success
image = open("screenshot.png", mode='wb')
image.write(data['png'])
image.close()
print "Screenshot saved to screenshot.png"
else:
print "Screenshot failed!"
# the reason for the error is sent as part of the HTTP response in the X-Error header but it is not exposed by this library
# quicker way to save a screenshot
info = browshot.simple_file('http://mobilito.net/', "mobilito.png", { 'cache': 0, 'instance_id': 65, 'screen_width': 1280, 'screen_height': 1024 }) # no cache, premium browser
if info['file'] != '':
print "Screenshot saved to %s" % info['file']
else:
print "The screenshot failed"
# -*- coding: utf-8 -*-
#######################
# WARNING
# Running this code sample will cost you Browshot credits
#######################
from browshot import BrowshotClient
import time
browshot = BrowshotClient('my_api_key')
screenshot = browshot.screenshot_create('http://www.google.com/', { 'instance_id': 12, 'size': 'page' }) # all default parameters, instance_id = 12 (free)
# If the screenshot is already in cache, it could be finished already. Otherwise, wait longer
while screenshot['status'] != 'finished' and screenshot['status'] != 'error':
print "Wait...";
time.sleep(10)
screenshot = browshot.screenshot_info(screenshot['id'])
# screenshot is done: finished (sucessful) or error (failed)
if screenshot['status'] == 'error':
print "Screenshot failed: " + screenshot['error'] # display the reason for the error
else: # request the thumbnail
image = browshot.screenshot_thumbnail(screenshot['id'])
# save the screenshot
fp = open("browshot.png", mode='wb')
fp.write(image)
fp.close()
# -*- coding: utf-8 -*-
#######################
# WARNING
# Running this code sample will cost you Browshot credits
#######################
from browshot import BrowshotClient
browshot = BrowshotClient('my_api_key')
info = browshot.simple_file('http://www.google.com/', 'google-640.png', { 'width': 640, 'height': 480 })
if info['file'] == '' or info['code'] != 200:
print "Screenshot failed"
else:
print "Thumbnail saved at %s" % info['file']
# -*- coding: utf-8 -*-
from browshot import BrowshotClient
import time
browshot = BrowshotClient('my_api_key')
screenshot = browshot.screenshot_create('http://www.google.com/', { 'instance_id': 12, 'size': 'screen' }) # all default paramters, instance_id = 12 (free)
# If the screenshot is already in cache, it could be finished already. Otherwise, wait longer
while screenshot['status'] != 'finished' and screenshot['status'] != 'error':
print "Wait..."
time.sleep(10)
screenshot = browshot.screenshot_info(screenshot['id'])
# screenshot is done: finished (sucessful) or error (failed)
if screenshot['status'] == 'error':
print "Screenshot failed: " + screenshot['error'] # display the reason for the error
else: # request the thumbnail
browshot.screenshot_thumbnail_file(screenshot['id'], '/tmp/google-640.png', { 'width': 640, 'height': 480 })
print "Screenshot was saved to /tmp/google-640.png"
no credit card required
Browshot is a web service to create real time web screenshots in a multitude of virtual devices, including mobile devices like the iPhone 3 & 4, iPad, Android Nexus, etc.
You can use the web dashboard, or our full-featured API.
Real time screenshots
15+ mobile devices: iPhone, iPad, Android, etc.
30+ desktop resolutions
Fast and reliable
Thumbnails of any size, any ratio
Full API, open-source libraries