Debian lenny version packages
[pkg-perl] / deb-src / libwww-mechanize-perl / libwww-mechanize-perl-1.34 / lib / WWW / Mechanize / Cookbook.pod
1 =head1 NAME
2
3 WWW::Mechanize::Cookbook - Recipes for using WWW::Mechanize
4
5 =head1 INTRODUCTION
6
7 First, please note that many of these are possible just using
8 L<LWP::UserAgent>.  Since C<WWW::Mechanize> is a subclass of
9 L<LWP::UserAgent>, whatever works on C<LWP::UserAgent> should work
10 on C<WWW::Mechanize>.  See the L<lwpcook> man page included with
11 the L<libwww-perl> distribution.
12
13 =head1 BASICS
14
15 =head2 Launch the WWW::Mechanize browser
16
17     use WWW::Mechanize;
18
19     my $mech = WWW::Mechanize->new( autocheck => 1 );
20
21 The C<< autocheck => 1 >> tells Mechanize to die if any IO fails,
22 so you don't have to manually check.  It's easier that way.  If you
23 want to do your own error checking, leave it out.
24
25 =head2 Fetch a page
26
27     $mech->get( "http://search.cpan.org" );
28     print $mech->content;
29
30 C<< $mech->content >> contains the raw HTML from the web page.  It
31 is not parsed or handled in any way, at least through the C<content>
32 method.
33
34 =head2 Fetch a page into a file
35
36 Sometimes you want to dump your results directly into a file.  For
37 example, there's no reason to read a JPEG into memory if you're
38 only going to write it out immediately.  This can also help with
39 memory issues on large files.
40
41     $mech->get( "http://www.cpan.org/src/stable.tar.gz",
42                 ":content_file" => "stable.tar.gz" );
43
44 =head2 Fetch a password-protected page
45
46 Generally, just call C<credentials> before fetching the page.
47
48     $mech->credentials( 'admin' => 'password' );
49     $mech->get( 'http://10.11.12.13/password.html' );
50     print $mech->content();
51
52 =head1 LINKS
53
54 =head2 Find all image links
55
56 Find all links that point to a JPEG, GIF or PNG.
57
58     my @links = $mech->find_all_links(
59         tag => "a", url_regex => qr/\.(jpe?g|gif|png)$/i );
60
61 =head2 Find all download links
62
63 Find all links that have the word "download" in them.
64
65     my @links = $mech->find_all_links(
66         tag => "a", text_regex => qr/\bdownload\b/i );
67
68 =head1 APPLICATIONS
69
70 =head2 Check all pages on a web site
71
72 Use Abe Timmerman's L<WWW::CheckSite>
73 L<http://search.cpan.org/dist/WWW-CheckSite/>
74
75 =head1 AUTHORS
76
77 Copyright 2005 Andy Lester C<< <andy@petdance.com> >>
78
79 Later contributions by Peter Scott, Mark Stosberg and others.
80
81 =cut