Blame view

samples/screenshot.coffee 833 Bytes
1
###
2 3 4 5
This script will capture a screenshot of a twitter account page
Usage: $ casperjs screenshot.coffee <twitter-account> <filename.[jpg|png|pdf]>
###

6
casper = require("casper").create
7 8 9 10
    viewportSize:
        width: 1024
        height: 768

11 12
twitterAccount = casper.cli.get 0
filename       = casper.cli.get 1
13

14
if not twitterAccount or not filename or not /\.(png|jpg|pdf)$/i.test filename
15
    casper
16
        .echo("Usage: $ casperjs screenshot.coffee <twitter-account> <filename.[jpg|png|pdf]>")
17
        .exit(1)
18

19 20
casper.start "https://twitter.com/#{twitterAccount}", ->
    @waitForSelector ".stream-container", (->
21
        @captureSelector filename, "html"
22
        @echo "Saved screenshot of #{@getCurrentUrl()} to #{filename}"
23 24 25 26
    ), (->
        @die("Timeout reached. Fail whale?")
        @exit()
    ), 12000
27 28

casper.run()