NAME

WWW::Mechanize::Shell - A crude shell for WWW::Mechanize

SYNOPSIS

DESCRIPTION

This module implements a www-like shell above WWW::Mechanize and also has the capability to output crude Perl code that recreates the recorded session. Its main use is as an interactive starting point for automating a session through WWW::Mechanize.

It has "live" display support for Microsoft Internet Explorer on Win32, if anybody has an idea on how to implement this for other browsers, I'll be glad to build this in - from what I know, you cannot write raw HTML into any other browser window.

The cookie support is there, but no cookies are read from your existing sessions. See HTTP::Cookies on how to implement reading/writing your current browser cookies.

COMMANDS

The shell implements various commands :

exit

See "quit"

restart

Restart the shell.

This is mostly useful when you are modifying the shell itself.

get

Download a specific URL.

This is used as the entry point in all sessions

Syntax: get URL

content

Display the HTML for the current page

This is used as the entry point in all sessions.

Display all links on a page

parse

Dump the output of HTML::TokeParser of the current content

forms

Display all forms on the current page

dump

Dump the values of the current form

value

Set a form value

Syntax: value NAME [VALUE]

submit

Clicks on the button labeled "submit"

click

Clicks on the button named NAME.

No regular expression expansion is done on NAME.

Syntax: click NAME

open

Open a link on the current page

It opens the link whose text is matched by RE, and displays all links if more than one matches.

Syntax: open RE

back

Go back one page in history.

browse

Open Internet Explorer with the current page

Displays the current page in Microsoft Internet Explorer. No provision is currently made about IE not being available.

set

Sets a shell option

Syntax: set OPTION [value]

history

Displays your current session history

fillout

Fill out the current form

Interactively asks the values hat have no preset value via the autofill command.

table

Display a table described by the columns COLUMNS.

Syntax: table COLUMNS

Example: table Product Price Description

If there is a table on the current page that has in its first row the three columns Product, Price and Description (not necessarily in that order), the script will display these columns of the whole table.

HTML::TableExtract is needed for this feature.

tables

Display a list of tables.

Syntax: tables

This command will display the top row for every table on the current page. This is convenient if you want to find out what the exact spellings for each column are.

The command does not always work nice, for example if a site uses tables for layout, it will be harder to guess what tables are irrelevant and what tables are relevant.

HTML::TableExtract is needed for this feature.

cookies

Set the cookie file name

Syntax: cookies FILENAME

autofill

Define an automatic value

Sets a form value to be filled automatically. The NAME parameter is the WWW::Mechanize::FormFiller::Value subclass you want to use. For session fields, Keep is a good candidate, for interactive stuff, Ask is a value implemented by the shell.

Syntax: autofill NAME [PARAMETERS]

Examples:

autofill login Fixed corion
autofill password Ask
autofill selection Random
autofill session Keep

eval

Evaluate Perl code and print the result

Syntax: eval CODE

source

Execute a batch of commands from a file.

Syntax: source FILENAME

SAMPLE SESSIONS

Entering values

# Search for a term on Google
get http://www.google.com
value q "Corions Homepage"
click btnG
history
# (yes, this is a bad example of automating, as Google
#  already has a Perl API. But other sites don't)

Retrieving a table

get http://www.perlmonks.org
open "/Saints in/"
table User Experience Level
history
# now you have a program that gives you a csv file of
# that table.

GENERATED SCRIPTS

The history command outputs a skeleton script that reproduces your actions as done in the current session. It pulls in WWW::Mechanize::FormFiller, which is possibly not needed. You should add some error and connection checking afterwards.

PROXY SUPPORT

Currently, the proxy support is realized via a call to the env_proxy method of the WWW::Mechanize object, which loads the proxies from the environment. There is no provision made to prevent using proxies (yet). The generated scripts also load their proxies from the environment.

ONLINE HELP

The online help feature is currently a bit broken in Term::Shell, but a fix is in the works. Until then, you can reenable the dynamic online help by patching Term::Shell :

Remove the three lines

  my $smry = exists $o->{handlers}{$h}{smry}
? $o->summary($h)
: "undocumented";

in sub run_help and replace them by

my $smry = $o->summary($h);

EXPORT

None by default.

COPYRIGHT AND LICENSE

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

Copyright (C) 2002,2003 Max Maischein

AUTHOR

Max Maischein, <corion@cpan.org>

Please contact me if you find bugs or otherwise improve the module. More tests are also very welcome !

SEE ALSO

WWW::Mechanize,WWW::Mechanize::FormFiller