{
    "mode": "perldoc",
    "parameter": "WWW::Mechanize::Cookbook",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/WWW%3A%3AMechanize%3A%3ACookbook/json",
    "generated": "2026-06-13T12:02:22Z",
    "sections": {
        "NAME": {
            "content": "WWW::Mechanize::Cookbook - Recipes for using WWW::Mechanize\n",
            "subsections": []
        },
        "VERSION": {
            "content": "version 2.06\n",
            "subsections": []
        },
        "INTRODUCTION": {
            "content": "First, please note that many of these are possible just using LWP::UserAgent. Since\n\"WWW::Mechanize\" is a subclass of LWP::UserAgent, whatever works on \"LWP::UserAgent\" should work\non \"WWW::Mechanize\". See the lwpcook man page included with the libwww-perl distribution.\n",
            "subsections": []
        },
        "BASICS": {
            "content": "",
            "subsections": [
                {
                    "name": "Launch the WWW::Mechanize browser",
                    "content": "use WWW::Mechanize;\n\nmy $mech = WWW::Mechanize->new( autocheck => 1 );\n\nThe \"autocheck => 1\" tells Mechanize to die if any IO fails, so you don't have to manually\ncheck. It's easier that way. If you want to do your own error checking, leave it out.\n"
                },
                {
                    "name": "Fetch a page",
                    "content": "$mech->get( \"http://search.cpan.org\" );\nprint $mech->content;\n\n\"$mech->content\" contains the raw HTML from the web page. It is not parsed or handled in any\nway, at least through the \"content\" method.\n"
                },
                {
                    "name": "Fetch a page into a file",
                    "content": "Sometimes you want to dump your results directly into a file. For example, there's no reason to\nread a JPEG into memory if you're only going to write it out immediately. This can also help\nwith memory issues on large files.\n\n$mech->get( \"http://www.cpan.org/src/stable.tar.gz\",\n\":contentfile\" => \"stable.tar.gz\" );\n"
                },
                {
                    "name": "Fetch a password-protected page",
                    "content": "Generally, just call \"credentials\" before fetching the page.\n\n$mech->credentials( 'admin' => 'password' );\n$mech->get( 'http://10.11.12.13/password.html' );\nprint $mech->content();\n"
                }
            ]
        },
        "LINKS": {
            "content": "",
            "subsections": [
                {
                    "name": "Find all image links",
                    "content": "Find all links that point to a JPEG, GIF or PNG.\n\nmy @links = $mech->findalllinks(\ntag => \"a\", urlregex => qr/\\.(jpe?g|gif|png)$/i );\n"
                },
                {
                    "name": "Find all download links",
                    "content": "Find all links that have the word \"download\" in them.\n\nmy @links = $mech->findalllinks(\ntag => \"a\", textregex => qr/\\bdownload\\b/i );\n"
                }
            ]
        },
        "ADVANCED": {
            "content": "",
            "subsections": [
                {
                    "name": "See what will be sent without actually sending anything",
                    "content": "$mech->addhandler(\"requestsend\", sub { shift->dump; exit; });\n$mech->get(\"http://www.example.com\");\n"
                }
            ]
        },
        "SEE ALSO": {
            "content": "WWW::Mechanize\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Andy Lester <andy at petdance.com>\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENSE": {
            "content": "This software is copyright (c) 2004 by Andy Lester.\n\nThis is free software; you can redistribute it and/or modify it under the same terms as the Perl\n5 programming language system itself.\n",
            "subsections": []
        }
    },
    "summary": "WWW::Mechanize::Cookbook - Recipes for using WWW::Mechanize",
    "flags": [],
    "examples": [],
    "see_also": []
}