Dr.Avalanche
Dr.Avalanche

Reputation: 2006

Perl - WWW::Mechanize::Firefox - Open link in new tab

Using the $mech->find_all_links_dom method I get an array of links on a page. For each $link in the array I want to open it in a new tab. I can't figure out how to do this, and advice would be great.

Upvotes: 1

Views: 775

Answers (1)

slayedbylucifer
slayedbylucifer

Reputation: 23532

This is one way to work:

#!/usr/bin/perl -w
use strict;
use WWW::Mechanize::Firefox;

my @array = <DATA>;

foreach (@array)
{
    my $mech = WWW::Mechanize::Firefox->new(    
                        activate => 1,  # bring the tab to the foreground
                        autoclose => 0  # to prevent autoclosing of the Tab
                        ); 
    $mech->get($_);
}

__DATA__
www.google.com
www.yahoo.com

AFAIK, WWW::Mechanize::Firefox opens the page in the same tab for a given object ($mech). So, I run a foreach loop and create a new object for each link. This may not be the BEST approach but this works.

Upvotes: 1

Related Questions