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

787 views Asked by At

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.

1

There are 1 answers

1
slayedbylucifer On BEST ANSWER

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.