WWW/Mechanize/Chrome/Examples.pm untested

filter: Statementstmt 0.0% 0 / 5 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 1 Podpod n/a totaltotal 0.0% 0 / 6 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
CRAP 2.0
1 package WWW::Mechanize::Chrome::Examples;
2  
3 ###############################################################################
4 #
5 # Examples - WWW::Mechanize::Chrome examples.
6 #
7 # A documentation only module showing the examples that are
8 # included in the WWW::Mechanize::Chrome distribution. This
9 # file was generated automatically via the gen_examples_pod.pl
10 # program that is also included in the examples directory.
11 #
12 # Copyright 2000-2010, John McNamara, jmcnamara@cpan.org
13 #
14 # Documentation after __END__
15 #
16  
17 use strict;
18 our $VERSION = '0.78';
19  
20 1;
21  
22 __END__
23  
24 =pod
25  
26 =head1 NAME
27  
28 Examples - WWW::Mechanize::Chrome example programs.
29  
30 =head1 DESCRIPTION
31  
32 This is a documentation only module showing the examples that are
33 included in the L<WWW::Mechanize::Chrome> distribution.
34  
35 This file was auto-generated via the C<gen_examples_pod.pl>
36 program that is also included in the examples directory.
37  
38 =head1 Example programs
39  
40 The following is a list of the 5 example programs that are included in the WWW::Mechanize::Chrome distribution.
41  
42 =over
43  
44 =item * L<Example: url-to-image.pl> Take a screenshot of a website
45  
46 =item * L<Example: html-to-pdf.pl> Convert HTML to PDF
47  
48 =item * L<Example: dump-links.pl> Dump links on a webpage
49  
50 =item * L<Example: sendkeys.pl> Send keystrokes to a page
51  
52 =item * L<Example: javascript.pl> Execute Javascript in the webpage context
53  
54 =back
55  
56 =head2 Example: url-to-image.pl
57  
58 #!/usr/bin/perl
59 use strict;
60 use File::Spec;
61 use File::Basename 'dirname';
62 use Log::Log4perl qw(:easy);
63 use WWW::Mechanize::Chrome;
64
65 my $mech = WWW::Mechanize::Chrome->new();
66
67 sub show_screen() {
68 my $page_png = $mech->content_as_png();
69
70 my $fn= File::Spec->rel2abs(dirname($0)) . "/screen.png";
71 open my $fh, '>', $fn
72 or die "Couldn't create '$fn': $!";
73 binmode $fh, ':raw';
74 print $fh $page_png;
75 close $fh;
76
77 #system(qq(start "Progress" "$fn"));
78 };
79
80 $mech->get('http://act.yapc.eu/gpw2017');
81
82 show_screen;
83
84 =head1 NAME
85
86 url-to-image.pl
87
88 =head1 SYNOPSIS
89
90 perl url-to-image.pl
91
92 =head1 DESCRIPTION
93
94 This example fetches a web page and creates a screenshot in PNG format
95 in the script's directory.
96  
97  
98 Download this example: L<https://metacpan.org/release/CORION/WWW-Mechanize-Chrome-0.78/source/examples/url-to-image.pl>
99  
100 =head2 Example: html-to-pdf.pl
101  
102 #!perl -w
103 use strict;
104 use Log::Log4perl qw(:easy);
105 use WWW::Mechanize::Chrome;
106
107 my $url = shift @ARGV
108 or die "Usage: perl $0 <url>\n";
109
110 my $mech = WWW::Mechanize::Chrome->new(
111 headless => 1, # otherwise, PDF printing will not work
112 );
113
114 print "Loading $url";
115 $mech->get($url);
116
117 my $fn= 'screen.pdf';
118 my $page_pdf = $mech->content_as_pdf(
119 filename => $fn,
120 );
121 print "\nSaved $url as $fn\n";
122
123 =head1 NAME
124
125 html-to-pdf.pl
126
127 =head1 SYNOPSIS
128
129 perl html-to-pdf.pl https://www.perl.org/
130
131 =head1 DESCRIPTION
132
133 This example takes an URL from the command line, renders it and and
134 saves it as a PDF file in the current directory.
135  
136  
137 Download this example: L<https://metacpan.org/release/CORION/WWW-Mechanize-Chrome-0.78/source/examples/html-to-pdf.pl>
138  
139 =head2 Example: dump-links.pl
140  
141 #!/usr/bin/perl
142 use strict;
143 use Log::Log4perl qw(:easy);
144 use WWW::Mechanize::Chrome;
145
146 my $mech = WWW::Mechanize::Chrome->new();
147
148 $mech->get_local('links.html');
149
150 sleep 5;
151
152 print $_->get_attribute('href'), "\n\t-> ", $_->get_attribute('innerHTML'), "\n"
153 for $mech->selector('a.download');
154
155 =head1 NAME
156
157 dump-links.pl - Dump links on a webpage
158
159 =head1 SYNOPSIS
160
161 From the examples directory:
162
163 perl dump-links.pl
164
165 =head1 DESCRIPTION
166
167 This program demonstrates how to read elements out of the Chrome DOM
168 and how to get at text within nodes. It prints links with the CSS
169 class "download" from a file provided with the distribution.
170
171
172 =cut
173  
174  
175 Download this example: L<https://metacpan.org/release/CORION/WWW-Mechanize-Chrome-0.78/source/examples/dump-links.pl>
176  
177 =head2 Example: sendkeys.pl
178  
179 #!perl -w
180 use strict;
181 use Log::Log4perl qw(:easy);
182 use WWW::Mechanize::Chrome;
183 Log::Log4perl->easy_init($ERROR);
184
185 my $mech = WWW::Mechanize::Chrome->new();
186
187 $mech->get( 'https://google.com' );
188
189 $mech->sendkeys( string => "test\r" );
190
191 $mech->sleep( 10 );
192
193 =head1 NAME
194
195 sendkeys.pl - send keystrokes to a page
196
197 =head1 SYNOPSIS
198
199 perl sendkeys.pl
200
201 =head1 DESCRIPTION
202
203 B<This program> demonstrates how to type some input into a text field
204 and then press the C<enter> key.
205
206 =cut
207  
208  
209 Download this example: L<https://metacpan.org/release/CORION/WWW-Mechanize-Chrome-0.78/source/examples/sendkeys.pl>
210  
211 =head2 Example: javascript.pl
212  
213 #!perl -w
214 use strict;
215 use Log::Log4perl qw(:easy);
216 use WWW::Mechanize::Chrome;
217
218 my $mech = WWW::Mechanize::Chrome->new();
219 $mech->get_local('links.html');
220
221 $mech->eval_in_page(<<'JS');
222 alert('Hello Frankfurt.pm');
223 JS
224
225 <>;
226
227 =head1 NAME
228
229 javascript.pl - execute Javascript in a page
230
231 =head1 SYNOPSIS
232
233 perl javascript.pl
234
235 =head1 DESCRIPTION
236
237 B<This program> demonstrates how to execute simple
238 Javascript in a page.
239
240 =cut
241  
242  
243 Download this example: L<https://metacpan.org/release/CORION/WWW-Mechanize-Chrome-0.78/source/examples/javascript.pl>
244  
245 =head1 AUTHOR
246  
247 Max Maischein C<corion@cpan.org>
248  
249 Contributed examples contain the original author's name.
250  
251 =head1 COPYRIGHT
252  
253 Copyright 2009-2026 by Max Maischein C<corion@cpan.org>.
254  
255 All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.
256  
257 =cut