根据标题关闭标签
Close Tab Based on Title
如何使用 WWW::Mechanize::Firefox
根据标题关闭标签页?
这是我目前拥有的:
my $ff = Firefox::Application->new();
my @tab_info = $ff->openTabs();
foreach my $tab (@tab_info) {
if($tab->{title} eq "TITLE HERE") {
$ff->closeTab($tab->{location});
}
}
closeTab() 的文档只是说 'Close the Given Tab',没有关于给定选项卡是什么的信息
是$ff->closeTab($tab->{tab})
。例如,参见 Cookbook。一个完整的程序:
use WWW::Mechanize::Firefox;
my $ff = Firefox::Application->new();
my $title_to_close = "Title of the page to close ...";
# This will pull in all currently opened tabs
my @tabs = $ff->openTabs();
foreach my $tab (@tabs) {
if ($tab->{title} =~ /$title_to_close/) {
print "Close tab: $tab->{title}";
$ff->closeTab($tab->{tab});
}
}
更简洁:
$ff->closeTab($_->{tab}) for grep { $_->{title} eq 'TITLE HERE' } $ff->openTabs;
如何使用 WWW::Mechanize::Firefox
根据标题关闭标签页?
这是我目前拥有的:
my $ff = Firefox::Application->new();
my @tab_info = $ff->openTabs();
foreach my $tab (@tab_info) {
if($tab->{title} eq "TITLE HERE") {
$ff->closeTab($tab->{location});
}
}
closeTab() 的文档只是说 'Close the Given Tab',没有关于给定选项卡是什么的信息
是$ff->closeTab($tab->{tab})
。例如,参见 Cookbook。一个完整的程序:
use WWW::Mechanize::Firefox;
my $ff = Firefox::Application->new();
my $title_to_close = "Title of the page to close ...";
# This will pull in all currently opened tabs
my @tabs = $ff->openTabs();
foreach my $tab (@tabs) {
if ($tab->{title} =~ /$title_to_close/) {
print "Close tab: $tab->{title}";
$ff->closeTab($tab->{tab});
}
}
更简洁:
$ff->closeTab($_->{tab}) for grep { $_->{title} eq 'TITLE HERE' } $ff->openTabs;