Django Page Exporter documentation

Welcome to Django Page Exporter Documentation.

Developer Documentation

Installation

Install the Package

pip install page_exporter

Configuration

How to use

The followings SETTINGS should contain values as follow:

INSTALLED_APPS = (
    ...
    'page_exporter',
    ...
)

url.py should contain:

urlpatterns = patterns(
    ...
    (r'^capture/', include('page_exporter.urls')),
    ...
)

you can ovverride default configuration using:

PAGE_EXPORTER_CAPTURE_SCRIPT = './capture.js'
PAGE_EXPORTER_CLI_ARGS = []
PAGE_EXPORTER_PHANTOMJS_CMD = None
PAGE_EXPORTER_WAIT = '2000'

Parameters

You can then obtain a screenshot using the following GET or POST parameters :

url

The website URL to capture. This can be a fully qualified URL, or the name of a URL to be reversed in your Django project. Note: do not forget to encode the url.

selector

CSS3 selector. It will restrict the screenshot to the selected element.

method

HTTP method to be used (default: GET)

width

Viewport width (default: 1400)

height

Viewport height (default: 900)

data

HTTP data to be posted (default: {})

wait

milliseconds used as timeout before capture

page_status

string. The screenshot will be performed only once document.page_status is equal to the passed value. Typical usage: if your page contains a heavy javascript processing, you can add the page_status variable at the end of the processing to make sure the screenshot will get the page properly rendered.

render

png (default), pdf (will use media print css), jpg (PIL needed)

cookie_name, cookie_value, cookie_domain

cookie information to send for authenticated pages

page_exporter package

Submodules

page_exporter.config module

class page_exporter.config.Settings(prefix)[source]

Bases: object

page_exporter.urls module

page_exporter.utils module

exception page_exporter.utils.CaptureError[source]

Bases: exceptions.Exception

exception page_exporter.utils.UnsupportedImageFormat[source]

Bases: exceptions.Exception

page_exporter.utils.image_mimetype(render)[source]
page_exporter.utils.image_postprocess(imagefile, output, size, crop, render)[source]

Resize and crop captured image, and saves to output. (can be stream or filename)

page_exporter.utils.page_capture(stream, url, method=None, width=None, height=None, selector=None, data=None, waitfor=None, size=None, crop=None, render='png', wait=None, cookie_name=None, cookie_value=None, cookie_domain=None, page_status=None)[source]

Captures web pages using phantomjs

page_exporter.utils.parse_render(render)[source]
page_exporter.utils.parse_size(size_raw)[source]
page_exporter.utils.parse_url(request, url)[source]

Parse url URL parameter.

page_exporter.utils.phantomjs_command()[source]
page_exporter.utils.phantomjs_command_kwargs()[source]

will construct kwargs for cmd

page_exporter.utils.process_phantomjs_stdout(stdout)[source]

Parse and digest capture script output.

page_exporter.views module

page_exporter.views.capture(request)[source]

Module contents

page_exporter.get_git_changeset()[source]

Returns a numeric identifier of the latest git changeset.

The result is the UTC timestamp of the changeset in YYYYMMDDHHMMSS format. This value isn’t guaranteed to be unique, but collisions are very unlikely, so it’s sufficient for generating the development version numbers.

page_exporter.get_version()[source]

Derives a PEP386-compliant version number from VERSION.