简体   繁体   English

根据标题关闭标签

[英]Close Tab Based on Title

How would I close a tab based on it's title using WWW::Mechanize::Firefox ? 如何使用WWW::Mechanize::Firefox基于标题关闭选项卡?

Here is what I currently have: 这是我目前拥有的:

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});
    }
}

The documentation for closeTab() just says 'Close the Given Tab' with no information on what the given tab is closeTab()的文档仅显示“关闭给定选项卡”,而没有有关给定选项卡是什么的信息

It is $ff->closeTab($tab->{tab}) . 它是$ff->closeTab($tab->{tab}) See the Cookbook , for example. 例如,参见菜谱 A complete program: 一个完整的程序:

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM