plainblack.com
Username Password
search
Bookmark and Share
Subscribe

WWW::Mechanize

If you're looking for a swiss knife to acces, test, to expand content or get reports from your WebGUI server or if you like to use the browser functions from within a program, have a look at WWW::Mechanize.

It has a bunch of functions and also provides a shell (WWW::Mechanize::Shell) which could write scripts for you.

With a few commands you can login, fetch, search and also add or edit assets.

The following text contains some examples:

#!/usr/bin/perl
use strict;
use warnings;

use WWW::Mechanize;

#-------------------------- my credentials
my $url = "http://your_website/";
my $username = "admin";
my $password = "XXXXX";

# functions to use
my $start="?op=auth;method=init";
my $adminon="?op=switchOnAdmin";

my $add_a_prototype="/your_path?func=add;class=WebGUI::Asset::Wobject::Article;prototype=hnJg91aqV4xjHA5w1OzBAQ";
#---------------------------------------------------------------
my $mech = WWW::Mechanize->new( autocheck => 1 );

# get the login startpage
$mech->get($url.$start);

# login
$mech->form_number(1);
$mech->field("username" => $username);
$mech->field("identifier" => $password);
$mech->click();


# admin on
$mech->get($url.$adminon);

#------------------------------------------ some examples

# have a look at the last news article
$mech->follow_link( url_regex => qr/news/i );
print $mech->content(format=>'text');

# get a link list ( each link is a WWW::Mechanize::Link object )
my @link = $mech->links();
# list the add-links
for my $i (0..$#link){
    next unless $link[$i]->url() =~ /func=add/;
    print $link[$i]->url()."        ";
    print $link[$i]->text()."\n";
}
# add a prototype
$mech->get($url.$add_a_prototype);
$mech->field("title","TEST MECHANIZE");
$mech->field("saveAndReturn","Save");
$mech->click();

 

Keywords: command line access testing tools

Search | Most Popular | Recent Changes | Wiki Home
© 2023 Plain Black Corporation | All Rights Reserved