GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  WWW::MECHANIZE::PHANTOMJS::EXAMPLES (3)

.ds Aq ’

NAME

Examples - WWW::Mechanize::PhantomJS example programs.

CONTENTS

DESCRIPTION

This is a documentation only module showing the examples that are included in the WWW::Mechanize::PhantomJS distribution.

This file was auto-generated via the gen_examples_pod.pl program that is also included in the examples directory.

Example programs

The following is a list of the 4 example programs that are included in the WWW::Mechanize::PhantomJS distribution.
o Example: url-to-image.pl Take a screenshot of a website
o Example: html-to-pdf.pl Convert HTML to PDF
o Example: dump-links.pl Dump links on a webpage
o Example: javascript.pl Execute Javascript in the webpage context

    Example: url-to-image.pl



    use strict;
    use File::Spec;
    use File::Basename dirname;
    use WWW::Mechanize::PhantomJS;
   
    my $mech = WWW::Mechanize::PhantomJS->new(
        launch_arg => [ghostdriver/src/main.js ],
    );
   
    sub show_screen() {
        my $page_png = $mech->content_as_png();
   
        my $fn= File::Spec->rel2abs(dirname($0)) . "/screen.png";
        open my $fh, >, $fn
            or die "Couldnt create $fn: $!";
        binmode $fh, :raw;
        print $fh $page_png;
        close $fh;
       
        #system(qq(start "Progress" "$fn"));
    };
   
    $mech->get(http://act.yapc.eu/gpw2014);
   
    show_screen;



Download this example: <http://cpansearch.perl.org/src/CORION/WWW-Mechanize-PhantomJS-0.11/examples/url-to-image.pl>

    Example: html-to-pdf.pl



    #!perl -w
    use strict;
    use WWW::Mechanize::PhantomJS;
   
    my $mech = WWW::Mechanize::PhantomJS->new(
        launch_arg => [ghostdriver/src/main.js ],
    );
   
    for my $url (@ARGV) {
        print "Loading $url";
        $mech->get($url);
   
        my $fn= screen.pdf;
        my $page_pdf = $mech->content_as_pdf(
            filename => $fn,
        );
        print "\nSaved $url as $fn\n";
    };



Download this example: <http://cpansearch.perl.org/src/CORION/WWW-Mechanize-PhantomJS-0.11/examples/html-to-pdf.pl>

    Example: dump-links.pl



    use strict;
    use WWW::Mechanize::PhantomJS;
   
    my $mech = WWW::Mechanize::PhantomJS->new(
        launch_arg => [ghostdriver/src/main.js ],
    );
   
    $mech->get_local(links.html);
   
    sleep 5;
   
    print $_->get_attribute(href), "\n\t-> ", $_->get_attribute(innerHTML), "\n"
      for $mech->selector(a.download);
   
    =head1 NAME
   
    dump-links.pl - Dump links on a webpage
   
    =head1 SYNOPSIS
   
    dump-links.pl
   
    =head1 DESCRIPTION
   
    This program demonstrates how to read elements out of the PhantomJS
    DOM and how to get at text within nodes.
   
    =cut



Download this example: <http://cpansearch.perl.org/src/CORION/WWW-Mechanize-PhantomJS-0.11/examples/dump-links.pl>

    Example: javascript.pl



    #!perl -w
    use strict;
    use WWW::Mechanize::PhantomJS;
   
    my $mech = WWW::Mechanize::PhantomJS->new(
        launch_arg => [ghostdriver/src/main.js ],
    );
   
   
    $mech->get_local(links.html);
   
    print $mech->eval_in_page(<<JS);
        ["Just","another","Perl","Hacker"].join(" ");
    JS
   
    =head1 NAME
   
    javascript.pl - execute Javascript in a page
   
    =head1 SYNOPSIS
   
    javascript.pl
   
    =head1 DESCRIPTION
   
    B<This program> demonstrates how to execute simple
    Javascript in a page.
   
    =cut



Download this example: <http://cpansearch.perl.org/src/CORION/WWW-Mechanize-PhantomJS-0.11/examples/javascript.pl>

AUTHOR

Max Maischein corion@cpan.org

Contributed examples contain the original author’s name.

COPYRIGHT

Copyright 2009-2014 by Max Maischein corion@cpan.org.

All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 WWW::MECHANIZE::PHANTOMJS::EXAMPLES (3) 2016-04-03

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.