perlでIE操作 [perl]
perlのWin32::OLEでInternet Explorerを操作してみる。
お約束の宣言はこれ。文字コード変換もあわせて宣言する。起動時にエラーが出る人は、CPANでインストールしてね。やり方google先生にきくのがはやい。
Internet Explorerを起動してタイトルを表示してみる。
起動中のInternet Explorerのタイトルを変えてみる
タイトルから起動中のInternet Explorerを探す。
お約束の宣言はこれ。文字コード変換もあわせて宣言する。起動時にエラーが出る人は、CPANでインストールしてね。やり方google先生にきくのがはやい。
use utf8; use Win32::OLE; use Encode;
Internet Explorerを起動してタイトルを表示してみる。
#Internet Explorerを起動 my $ie=Win32::OLE->new('InternetExplorer.Application') or die Win32::OLE->LastError; #Internet Explorerを見えるようにする $ie->{Visible}=1; #タイトルを表示する。 my $title=decode("cp932",$ie->document->title); printf("%s\n",encode('utf-8',$title));
起動中のInternet Explorerのタイトルを変えてみる
#shellのOLEを生成 my $shell=Win32::OLE->new('Shell.Application') or die Win32::OLE->LastError; my $ie=0; #Windowを探索 for(my $i=0;$i<$shell->Windows->Count;$i++){ next if($shell->Windows($i) !~ /^Win32\:\:OLE.+/); # オブジェクトタイプ取得 my($ln,$cn)=Win32::OLE->QueryObjectType($shell->Windows($i)); next if($cn ne "IWebBrowser2"); my $fullname=decode("cp932",$shell->Windows($i)->FullName); $fullname=~tr/[A-Z]/[a-z]/; next if($fullname !~ /.*iexplore\.exe$/); $ie=$shell->Windows($i); last; } die "Internet Explorer is not found." if($ie==0); #タイトルを変更 $ie->document->{title}=encode("cp932","てすと");
タイトルから起動中のInternet Explorerを探す。
#shellのOLEを生成 my $shell=Win32::OLE->new('Shell.Application') or die Win32::OLE->LastError; my $ie=0; my $title="MSN Japan"; #Windowを探索 for(my $i=0;$i<$shell->Windows->Count;$i++){ next if($shell->Windows($i) !~ /^Win32\:\:OLE.+/); # オブジェクトタイプ取得 my($ln,$cn)=Win32::OLE->QueryObjectType($shell->Windows($i)); next if($cn ne "IWebBrowser2"); my $fullname=decode("cp932",$shell->Windows($i)->FullName); $fullname=~tr/[A-Z]/[a-z]/; next if($fullname !~ /.*iexplore\.exe$/); $wintitle=decode("cp932", $shell->Windows($i)->document->title); next if($wintitle ne $title); $ie=$shell->Windows($i); last; } die "Internet Explorer is not found." if($ie==0);
2012-02-05 19:42
nice!(0)
コメント(0)
トラックバック(0)
コメント 0