gpt4 book ai didi

windows - 如何使用 Perl 自动化现有的 Internet Explorer 实例?

转载 作者:可可西里 更新时间:2023-11-01 09:50:09 25 4
gpt4 key购买 nike

我正在努力控制 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”的句柄,但不知道下一步该做什么。

最佳答案

已更新:您走错了路。你需要的是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 .

关于windows - 如何使用 Perl 自动化现有的 Internet Explorer 实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1189227/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com