# phpman > man > WWW::Mechanize::Cookbook

## NAME
    [WWW::Mechanize::Cookbook](https://www.chedong.com/phpMan.php/perldoc/WWW%3A%3AMechanize%3A%3ACookbook/markdown) - Recipes for using [WWW::Mechanize](https://www.chedong.com/phpMan.php/perldoc/WWW%3A%3AMechanize/markdown)

## VERSION
    version 2.06

## INTRODUCTION
    First, please note that many of these are possible just using [LWP::UserAgent](https://www.chedong.com/phpMan.php/perldoc/LWP%3A%3AUserAgent/markdown). Since
    "[WWW::Mechanize](https://www.chedong.com/phpMan.php/perldoc/WWW%3A%3AMechanize/markdown)" is a subclass of [LWP::UserAgent](https://www.chedong.com/phpMan.php/perldoc/LWP%3A%3AUserAgent/markdown), whatever works on "[LWP::UserAgent](https://www.chedong.com/phpMan.php/perldoc/LWP%3A%3AUserAgent/markdown)" should work
    on "[WWW::Mechanize](https://www.chedong.com/phpMan.php/perldoc/WWW%3A%3AMechanize/markdown)". See the lwpcook man page included with the libwww-perl distribution.

## BASICS
### Launch the [WWW::Mechanize](https://www.chedong.com/phpMan.php/perldoc/WWW%3A%3AMechanize/markdown) browser
        use [WWW::Mechanize](https://www.chedong.com/phpMan.php/perldoc/WWW%3A%3AMechanize/markdown);

        my $mech = [WWW::Mechanize](https://www.chedong.com/phpMan.php/perldoc/WWW%3A%3AMechanize/markdown)->new( autocheck => 1 );

    The "autocheck => 1" tells Mechanize to die if any IO fails, so you don't have to manually
    check. It's easier that way. If you want to do your own error checking, leave it out.

### Fetch a page
        $mech->get( "<http://search.cpan.org>" );
        print $mech->content;

    "$mech->content" contains the raw HTML from the web page. It is not parsed or handled in any
    way, at least through the "content" method.

### Fetch a page into a file
    Sometimes you want to dump your results directly into a file. For example, there's no reason to
    read a JPEG into memory if you're only going to write it out immediately. This can also help
    with memory issues on large files.

        $mech->get( "<http://www.cpan.org/src/stable.tar.gz>",
                    ":content_file" => "stable.tar.gz" );

### Fetch a password-protected page
    Generally, just call "credentials" before fetching the page.

        $mech->credentials( 'admin' => 'password' );
        $mech->get( '<http://10.11.12.13/password.html>' );
        print $mech->content();

## LINKS
### Find all image links
    Find all links that point to a JPEG, GIF or PNG.

        my @links = $mech->find_all_links(
            tag => "a", url_regex => qr/\.(jpe?g|gif|png)$/i );

### Find all download links
    Find all links that have the word "download" in them.

        my @links = $mech->find_all_links(
            tag => "a", text_regex => qr/\bdownload\b/i );

## ADVANCED
### See what will be sent without actually sending anything
        $mech->add_handler("request_send", sub { shift->dump; exit; });
        $mech->get("<http://www.example.com>");

## SEE ALSO
    [WWW::Mechanize](https://www.chedong.com/phpMan.php/perldoc/WWW%3A%3AMechanize/markdown)

## AUTHOR
    Andy Lester <andy at petdance.com>

## COPYRIGHT AND LICENSE
    This software is copyright (c) 2004 by Andy Lester.

    This is free software; you can redistribute it and/or modify it under the same terms as the Perl
    5 programming language system itself.

