【问题标题】:How can I automate an existing instance of Internet Explorer using Perl?如何使用 Perl 自动化现有的 Internet Explorer 实例?
【发布时间】:2009-07-28 15:12:17
【问题描述】:

我正在努力控制一个 IE 预览控件,它是使用 perl 的外部 Windows 应用程序上的“Internet Explorer_Server”类。

Internet Explorer_Server 是窗口的类名,我用 Spy++ 找到了它。这是我的断言代码

$className = Win32::GUI::GetClassName($window); 
if ($className eq "Internet Explorer_Server") { 
    ... 
}

我可以使用Win32::GUI::GetWindow 获得那个“Internet Explorer_Server”的句柄,但不知道下一步该做什么。

【问题讨论】:

  • 你能解释一下 Internet Explorer_Server 是什么吗?
  • Internet Explorer_Server 是窗口的类名,我用 Spy++ 找到的。这是我的断言代码 $className = Win32::GUI::GetClassName($window); if ($className eq "Internet Explorer_Server") { ... }
  • @crowdy 我根据您的评论更新了我的答案。

标签: windows perl internet-explorer automation win32ole


【解决方案1】:

更新:你走错了路。你需要的是Win32::OLE

#!/usr/bin/perl

use strict;
use warnings;

use Win32::OLE;
$Win32::OLE::Warn = 3;

my $shell = get_shell();
my $windows = $shell->Windows;

my $count = $windows->{Count};

for my $item ( 1 .. $count ) {
    my $window = $windows->Item( $item );
    my $doc = $window->{Document};
    next unless $doc;
    print $doc->{body}->innerHTML;
}

sub get_shell {
    my $shell;
    eval {
        $shell = Win32::OLE->GetActiveObject('Shell.Application');
    };

    die "$@\n" if $@;

    return $shell if defined $shell;

    $shell = Win32::OLE->new('Shell.Application')
        or die "Cannot get Shell.Application: ",
               Win32::OLE->LastError, "\n";
}
__END__

因此,这段代码找到了一个带有Document 属性的窗口并打印了HTML。您必须决定要使用什么标准来查找您感兴趣的窗口。

ShellWindows documentation.

【讨论】:

  • 谢谢,但这并不是我想要的。我不想创建一个新的 IE 实例。我要IE的控件已经存在了。
【解决方案2】:

您可能想看看Win32::IE::Mechanize。我不确定您是否可以使用此模块控制现有 IE 窗口,但访问单个 URL 应该可以在大约五行代码中实现。

【讨论】:

    【解决方案3】:

    你看过 Samie http://samie.sourceforge.net/,因为这是一个控制 IE 的 perl 模块

    【讨论】:

    • sigh 我从哪里开始?让我们暂时忽略主页上的漫画人物...... Samie 不在 CPAN 上。当你想下载它时,你得到的只是一个 zip 文件,里面有一个 Windows 风格的安装程序。它像专有软件组件一样打包。说到这个,主页上没有显示许可证。
    猜你喜欢
    • 2010-10-16
    • 1970-01-01
    • 2020-05-13
    • 2012-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多